You can simply check the mainDiv if angular.element(document.querySelector('#mainDiv')).scope() not undefined , it means that angular is not yet initialized.
The code will look as follows.
CODE
function onEndRequest(sender, args) { //below flag will be undefined if app has not bootsrap by angular. var doesAppInitialized = angular.element(document.querySelector('#mainDiv')).scope(); if (angular.isUndefined(doesAppInitialized)) //if it is not angular.bootstrap($('#mainDiv'), ['defaultApp']); var rootscope = angular.element('#mainDiv').scope(); if (rootscope) { rootscope.$apply(); //I don't know why you are applying a scope.this may cause an issue } }
Update
Following the release of angular 1.3+ in late August 2015, he added performance improvements by disabling debugging information and disabling debugging information. Therefore, as a rule, we should enable the debuginfo parameter in false in order to have a good performance improvement in the production environment. I did not want to write too much about this, since it was already covered by @AdamMcCormick's answer, which is really cool.
Pankaj parkar
source share