javascript - Error: $digest already in progress -



javascript - Error: $digest already in progress -

i'm getting error while trying phone call

function myctrl1($scope, $location, $rootscope) { $scope.$on('$locationchangestart', function (event, next, current) { event.preventdefault(); var reply = confirm("are sure want leave page?"); if (answer) { $location.url($location.url(next).hash()); $rootscope.$apply(); } }); } myctrl1.$inject = ['$scope', '$location', '$rootscope'];

error is

error: $digest in progress

duplicated: prevent error $digest in progress when calling $scope.$apply()

that error getting means angular's dirty checking in progress.

most recent best practices should utilize $timeout if want execute code in next digest iteration:

$timeout(function() { // code want run in next digest });

previous response: (don't utilize approach)

use safe apply, this:

$rootscope.$$phase || $rootscope.$apply();

why don't invert condition?

$scope.$on('$locationchangestart', function (event, next, current) { if (confirm("are sure want leave page?")) { event.preventdefault(); } });

javascript angularjs angularjs-directive

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -