I am trying to access my angular scope and I keep getting the common issue :"$digest already in progress". I can't use $timeout because I have to be able to do this in the section of my html because I am using Kendo UI Grid and I have to initialize the grid in the html script section(I wish I could figure out how to do it all in my controller).
The code is pretty simple, so I don't know what else to try.
....
$(document).ready(function () {
var scope = $('[ng-controller="NewIncidentController"]').scope();
scope.$apply(function () {
scope.submitfailure = true;
});
});
Thanks.
2 Answers 2
Try using scope.$applyAsync().
1 Comment
scope.$apply
would call $digest
internally which would cause the error you met since Angular allows only one cycle of digest at a time. $timeout
service can execute your function in the next cycle of digest.
For your situation, you can use scope.$evalAsync
, which will execute the specified function in the on-going digest process, thus avoiding the exception.
scope.$apply(function () {scope.submitfailure = true;});
. Have you simply triedscope.submitfailure = true;
?