Getting error "Error: $rootScope:inprog Action Already In Progress" while set states var

1,510 views
Skip to first unread message

reyn...@gmail.com

unread,
Mar 6, 2014, 1:38:23 PM3/6/14
to ang...@googlegroups.com
I'm trying to set states variable from a directive but I get the error as title said, this is the code I made:

app.directive('country', ['$http', function($http) {
        return {
            restrict: 'C',
            link: function(scope, element, attrs) {
                element.change(function() {
                    $http.get(Routing.generate('states') + '/' + element.val()).success(function(data) {
                        if (data.message) {
                            scope.message = data.message;
                        } else {
                            scope.$apply(function() {
                                scope.states = data;
                            });
                        }
                        console.log(scope.states);
                    }).error(function(data, status, headers, config) {
                        if (status == '500') {
                            scope.message = "No hay conexión con el servidor.";
                        }
                    });
                });
            }
        }
    }]);

What's wrong?

ReynierPM
Mobile: +58 424-180.56.09

Aadithya C Udupa

unread,
Mar 7, 2014, 12:25:08 AM3/7/14
to ang...@googlegroups.com
Hi,
Since you are trying to force a digest cycle using 

scope.$apply(function() {
      scope.states = data;
});

It is throwing an error saying it is not necessary to call $apply(). Add just scope.states = data; and try again.
You would typically want to use $scope.$apply() only when you are trying to make AJAX requests outside Angular context.


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.



--
Regards,
Aadithya C Udupa
Reply all
Reply to author
Forward
0 new messages