0

I'm using AngularJS resource to call an API. When I get a list of items with the API, all shows well in my ng-grid. When I try to filter on for example employeename, angular returns me "digest already in progress". What could be the problem?

What I did to call the api is this:

'use strict';

angularApp.factory('absenceResource',['$resource',function($resource){
    var baseUrl = config.apiurl;
    var buildUrl = function(resourceUrl){
         return baseUrl + resourceUrl;
    };

    return $resource(buildUrl('api/absences/:employee'),
        {employee: '@employee'},
        {
            "update": {method: "PUT"}
        });
}]);

Then to call that resource:

'use strict';

angularApp.factory('absenceData',function(absenceResource, authService){
return{
    getAbsence: function(absenceId){
        return absenceResource.query({id: absenceId});
    },
    getAllAbsences: function(){
        return absenceResource.query();
    },
    getAllAbsencesForUser: function(user){
        return absenceResource.query({'employee': user});
    },
    update: function(absence){
        absenceResource.$update(absence);
    },
    save: function(absence){
        absenceResource.save(absence);
    }
};

Then in my controller I do this:

$scope.absencesForUser = absenceData.getAllAbsencesForUser("jurgen");

    //$scope.absences = absenceData.getAllAbsences();
    $scope.gridOptions = {
        data: 'absencesForUser'
    };

I then get the digest error.

I've searched for this problem, but all the problems that I've found had to do with $rootScope.apply and I don't use that.

Can somebody help me?

Jurgen Vandw
  • 631
  • 8
  • 27
  • 1
    Please post the relevant code in your question – thomaux Jun 04 '14 at 07:26
  • Not sure where can come the problem, first let's trouble shoot it. Can you indicate which are exactly the offending files form your project? If you could isolate it in only a project with a couple of files or plunkr that would help a lot. – Braulio Jun 04 '14 at 07:34
  • Can you try to use reource but just return the data on the success call of the reosource (you could use promises here), or just try raw $http, let's check if it can be an issue of using resource – Braulio Jun 04 '14 at 07:37
  • Can somebody help me with my plunker? I've put all the necessary files in the plunker, but get an unexpected token i error. My plunker is here: http://plnkr.co/edit/qwGkvNvz14UBFH8jUlD4?p=preview – Jurgen Vandw Jun 04 '14 at 11:31
  • Probably duplicate question. http://stackoverflow.com/questions/12729122/prevent-error-digest-already-in-progress-when-calling-scope-apply – Zouzias Jun 05 '14 at 07:18

0 Answers0