0

I have this directive as also known from other threads. Now I was running into an AngularJS apply exception:

Error: $rootScope:inprog Action Already In Progress $digest already in progress

Does anyone know how I can prevent this exception? I tried it with a trigger but with no success.

 (function() {
'use strict';

angular
    .module('myProject.common')
    .directive('asScrollTop', asScrollTop);

asScrollTop.$inject = ['chatService'];

function asScrollTop(chatService) {
    var directive = {
        restrict: 'A',
        scope: { 
            chatMessagesOfUser: '=',
            currentUser: '=',
            messagesPage: '='
            },
        link: link
    };
    return directive;

    ////////////

    function link(scope, element, attr) {
        console.log(element);
        var trigger = false;
        element.on('scroll', function() {

          if(element[0].scrollTop <= 0 && trigger == false) {
              trigger = true;
              var page = scope.messagesPage + 1;

              chatService.getChatMessagesOfUser(scope.currentUser.id, page).success(function(response) {
                  scope.chatMessagesOfUser = response;
                  scope.$apply();
                  trigger = false;
                }).error(function(data) {
                    console.log('error in asScroll.directive.js#link');
                });
          }
        });
      }
}
})();

1 Answer 1

0

That just means that you don't need to call scope.$apply(); because a digest is already occurring, so whatever you were trying to achieve with it is already happening. Just remove the line and things should work fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.