Taher Mestiri
Taher Mestiri

Reputation: 743

Ng-Repeat not updating after a Resource Query - $apply() is not working

I have a problem updating my view using ng-repeat that doesn't refresh after loading data from server using a query.

Here is my code:

Controller:

vm.getPage = function() { 
            rendezvousResource.query(vm.gridOptions, function(result) {
                vm.gridData.totalItems = result.total;
                vm.gridData.totalPages = result.last_page;
                vm.gridOptions.page = result.current_page;
                vm.gridOptions.data = result.data;
                vm.rendezvouss = result.data;
                // $scope.$apply();
            });

        };

View :

        <table ng-controller="RendezvousListCtrl as vm"  class="table table-hover">
            <thead>
                <tr>
                    <th>Client</th>
                    <th>Date Début</th>
                    <th>Date Fin</th> 
                    <th>Type RDV</th>
                    <th>Status</th>
                    <th>Notification</th>
                </tr>
            </thead>
            <tbody>  
                <tr ng-repeat="rendezvous in vm.rendezvouss">
                    <td>{{ rendezvous.nomClient }}</td> 
                    <td>{{ rendezvous.debut }}</td>
                    <td>{{ rendezvous.fin }}</td>
                    <td>{{ rendezvous.typerdv }}</td>
                    <td>{{ rendezvous.status }}</td> 
                    <td>{{ rendezvous.notification }}</td> 
                </tr>
            </tbody>
        </table>

I already tried to add $scope.$apply() but I get an : Error: error:inprog Action Already In Progress

I already tried $timeout inside the callback function but it doesn't work, outside the function applying it on getPage it says undefined is not a function.

I also tried to use .then and $promise.then but it answers also undefined is not a function.

Any help please? :)

Upvotes: 1

Views: 341

Answers (1)

Taher Mestiri
Taher Mestiri

Reputation: 743

My Controller has been instantiated two times (my mistake) but this is what caused the ngRepeat to not refresh.

To be able to see this, I installed AngularJS Batarang chrome extension. It offers a clean view of the scope and been able to see that my controller have been instantiated two times.

Upvotes: 0

Related Questions