ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Error: Controller 'uiGrid', required by directive 'uiGridRow'?

Open archerchiu opened this issue 12 years ago • 24 comments

Hello, I found an error when grid in bootstrap modal. As the grid in modal show the first time, everything is fine, but the second time rendering always print the error log: Error: [$compile:ctreq] Controller 'uiGrid', required by directive 'uiGridRow', can't be found! ... in console. Could you give me some hint or suggestions? 2014-10-13 09-00-58

archerchiu avatar Oct 13 '14 00:10 archerchiu

Could you provide a plunker perhaps of this? The tutorial: http://ui-grid.info/docs/#/tutorial/110_grid_in_modal does not have this behaviour, so it would be some interaction with your code, but we'd need an example to diagnose.

PaulL1 avatar Oct 14 '14 22:10 PaulL1

Thanks for response. Let me ask one question first, the modal html including grid should be $compile every time? May I put it in a script template, partial code like below.

<script type="text/ng-template" id="assistorModal">     
    <div class="modal" tabindex="-1" role="dialog">   
        <div class="modal-dialog modal-lg">    
            <div class="modal-content">       
                <div class="modal-body">
                    <form class="form-horizontal container-fluid" role="form">      
                        <div class="row">       
                            <button type="button" class="close" ng-click="$hide()">&times;</button>   
                            <button type="button" class="btn btn-primary" ng-click="assistor.setSymbol()">區間符號</button>   
                        </div>   
                    </form>   
                <div style="height:4px;"></div>   
                <div ui-grid="assistor.gridOpts" class="grid" ui-grid-selection ui-grid-resize-columns ui-grid-auto-resize></div>   
            </div>   
        </div>   
    </div>   
    </div>   
</script>

show grid modal js

    $scope.assistor.modal = $modal({
        template: 'assistorModal',
        show: false,
        backdrop: 'static',
        scope: $scope
      });
    $http.post(...).success(function (data) {
        // prepare the columnDefs and data dynamically ...
        $scope.assistor.gridOpts.columnDefs = cols;
        $scope.assistor.gridOpts.data = data.rsList;
        $scope.assistor.modal.$promise.then(function () {
          $scope.assistor.modal.show();
        });
    });
    ...

archerchiu avatar Oct 15 '14 02:10 archerchiu

I don't see any reason you couldn't, so long as you're not trying to manipulate the grid before the modal has shown. You'd also have to be careful that your various variables weren't holding a reference to the old grid when a new one is rendered - so look out for things like gridApi which might be pointing to the old grid (and therefore causing that grid not to be garbage collected, as well as giving errors if you called methods within it).

In my application I do something similar, but I put all the grid setup on the modal controller itself. That way when the modal goes away, so does the grid, and when I start a new modal, it definitely has a new grid and new variables.

PaulL1 avatar Oct 15 '14 02:10 PaulL1

OK, I try to figure out of it. Thanks a lot.

archerchiu avatar Oct 15 '14 02:10 archerchiu

Assuming original question resolved, as no new comments for 3 weeks. Closing.

PaulL1 avatar Nov 07 '14 07:11 PaulL1

I'm getting the same error with a modal. Only happens the second time I open the window. I'm adding rows to the grid through a $scope.$on event. Not sure what the difference would be. I'm guessing some kind of issue with it cloning or copying the grid object. The grid itself works fine, just throws the nasty error. If I put together a plunkr or jsfiddle how high would the priority be on this?

Right now I get around it by passing in an object that contains the grid.data. It works for one grid. Problem is, I need to update a grid on another controller. My broadcast has no knowledge of the other grid (which is a good design IMHO). Tying the data this way is also coupling the grid and other controller together which sucks.

I'd even go with a way to just suppress the error. I might look into this next as there seems to be nothing "bad" happening to the grid to affect its usability or function. Everything's working fine.

        function addFacility(newFacility) {
            var broadcast = { facilityId: newFacility.facilityId, areaSize: newFacility.usingSize, tenantId: data.tenantId, tenantName: data.tenantName, data: tf.facilityTenants.data };
            tf.newAreaSize = 1;
            tf.newDescription = '';
            common.$broadcast('newFacility', broadcast);
        }

        $scope.$on('newFacility', (event, newFacility) => {
            if ('data' in tf.facilityTenants) {
                newFacility.data.unshift(newFacility);
            } else {
                newFacility.data = [newFacility];
            }
            _.remove(tf.availableFacilityTenants, (facility: fResponse.IFacility) => {
                return facility.facilityId == newFacility.facilityId;
            });
        })

rballonline avatar Jan 29 '15 17:01 rballonline

I am getting the same 'Error: [$compile:ctreq] Controller 'uiGrid', required by directive 'uiGridHeaderCell', can't be found!' error described above when trying to implement a custom filter modal. The same error is reproducable in the custom filter tutorial (http://ui-grid.info/docs/#/tutorial/306_custom_filters). These errors don't seem to cause any functionality problems but it would be great to have a way to get rid of them.

Produced by my custom filter modal: image

Prouded by the custom filter modal in the Grid UI tutorial (click on the '...' on the Age header). The error will display on the second time. image

aceb694 avatar Sep 23 '15 04:09 aceb694

Have the same issue with $mdDialog of Angular material

MaximShoustin avatar Nov 21 '15 22:11 MaximShoustin

i am having this problem as well, i believe it's a conflict with something else

ghost avatar Dec 01 '15 18:12 ghost

I also have this issue.

miranl avatar Dec 09 '15 15:12 miranl

I also can see this issue under custom filters. If you click the age column button again after filtering.

pacificeyes avatar Dec 13 '15 16:12 pacificeyes

Hi guys, I solved the error with.. <div data-ng-if="!refresh" data-ui-grid="whatever.gridOptions"></div>

the bit of ng-if refresh was what I needed. it's a part of angular.

ghost avatar Dec 14 '15 19:12 ghost

please open another ticket for this error, I got the same issue.

thucnc avatar Jan 15 '16 05:01 thucnc

I got the same issue too.

yuxiaomin avatar Jan 23 '16 08:01 yuxiaomin

Guys - when you have an error, try to reproduce them on plnkr. If you can't, it is probably something with your code. If you can, someone could actually look into them. Can anyone reproduce this on plnkr?

YonatanKra avatar Jan 23 '16 09:01 YonatanKra

The issue shows up when use ui-grid with modal(I use angular strap, http://mgcrea.github.io/angular-strap/) . When the modal is dismissed the HTML DOM of the modal is removed but angular scope of the modal is not destroyed and left over. At this moment the error will start to happen.

If I open and close the modal repeatedly I can see this error more and more times.

I destroy the scope manually before the modal is hidden then the error will not show any more.

yuxiaomin avatar Jan 24 '16 02:01 yuxiaomin

Is there any solution for this issue, Or any alternative method ?

Nidhintt avatar Feb 10 '16 05:02 Nidhintt

I am getting the same error "Controller 'uiGrid', required by directive 'uiGridRow', can't be found!" http://plnkr.co/edit/Kq09kuEF2vFJyjwQ5uxC Just click "Show modal" 2 times.

kirill-korepanov avatar Apr 27 '16 16:04 kirill-korepanov

getting the same error - but with no modal. I just did a gulp rebuild on my app and it started happening

jmls avatar Apr 28 '16 09:04 jmls

Seeing the same thing on our app...no modal.

We are showing multiple "grids" in tabs. When the user rapidly switches between tabs, sometimes this error gets thrown. Will troubleshoot more but according to boilerplate angular error documentation, uiGrid controller is not yet created when uiGridRow is being rendered. Perhaps its in the destroy, that before leaving a tab, a uiGridRow is trying to render or access its uiGrid controller, but the uiGrid controller has already been disposed?

nkoterba avatar May 12 '16 18:05 nkoterba