Problem:
I am trying to load an Angular JS app in a bootstrap modal pane, and it is displaying strange behaviour on Internet Explorer (We have tested it on IE9 and 8).
we found that we were getting following errors :
** 'JSON' undefined ** object Errorundefined
SCRIPT5022: 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: function $locationWatch() {
var oldUrl = $browser.url();
var currentReplace = $location.$$replace;
if (!changeCounter || oldUrl != $location.absUrl()) {
changeCounter++;
$rootScope.$evalAsync(function() {
if ($rootScope.$broadcast('$locationChangeStart', $location.absUrl(), oldUrl).
defaultPrevented) {
$location.$$parse(oldUrl);
} else {
$browser.url($location.absUrl(), currentReplace);
afterLocationChange(oldUrl);
}
});
}
$location.$$replace = false;
return changeCounter;
}; newVal: 7; oldVal: 6"],["fn: function $locationWatch() {
var oldUrl = $browser.url();
var currentReplace = $location.$$replace;
if (!changeCounter || oldUrl != $location.absUrl()) {
changeCounter++;
$rootScope.$evalAsync(function() {
if ($rootScope.$broadcast('$locationChangeStart', $location.absUrl(), oldUrl).
defaultPrevented) {
$location.$$parse(oldUrl);
} else {
$browser.url($location.absUrl(), currentReplace);
afterLocationChange(oldUrl);
}
});
}
$location.$$replace = false;
return changeCounter;
}; newVal: 8; oldVal: 7"],["fn: function $locationWatch() {
var oldUrl = $browser.url();
var currentReplace = $location.$$replace;
if (!changeCounter || oldUrl != $location.absUrl()) {
changeCounter++;
$rootScope.$evalAsync(function() {
if ($rootScope.$broadcast('$locationChangeStart', $location.absUrl(), oldUrl).
defaultPrevented) {
$location.$$parse(oldUrl);
} else {
$browser.url($location.absUrl(), currentReplace);
afterLocationChange(oldUrl);
}
});
}
$location.$$replace = false;
return changeCounter;
}; newVal: 9; oldVal: 8"],["fn: function $locationWatch() {
var oldUrl = $browser.url();
var currentReplace = $location.$$replace;
if (!changeCounter || oldUrl != $location.absUrl()) {
changeCounter++;
$rootScope.$evalAsync(function() {
if ($rootScope.$broadcast('$locationChangeStart', $location.absUrl(), oldUrl).
defaultPrevented) {
$location.$$parse(oldUrl);
} else {
$browser.url($location.absUrl(), currentReplace);
afterLocationChange(oldUrl);
}
});
}
$location.$$replace = false;
return changeCounter;
}; newVal: 10; oldVal: 9"],["fn: function $locationWatch() {
var oldUrl = $browser.url();
var currentReplace = $location.$$replace;
if (!changeCounter || oldUrl != $location.absUrl()) {
changeCounter++;
$rootScope.$evalAsync(function() {
if ($rootScope.$broadcast('$locationChangeStart', $location.absUrl(), oldUrl).
defaultPrevented) {
$location.$$parse(oldUrl);
} else {
$browser.url($location.absUrl(), currentReplace);
afterLocationChange(oldUrl);
}
});
}
$location.$$replace = false;
return changeCounter;
}; newVal: 11; oldVal: 10"]]
and many other errors
So, we found that there are 3 problem on IE: 1) JSON was not available 2) Problem with Bootstraping application 3) Problem Rendering view
after going through Angular JS documentation and lots of threads from StackOverflow, such as :
http://docs.angularjs.org/guide/ie
'JSON' is undefined error in IE only
- JSON Parse Error on Internet Explorer
- Running AngularJS App on Internet Explorer 7
- http://docs.angularjs.org/guide/directive
We found that there are few common across all threads (also mentioned in AngulaJS IE guide): * Include JSON2/JSON3 pollyfills for IE * use ie-shiv, and pre-declare custom tags (we are using custom typeahead directive, with restrict: 'E', replace: true) * use other IE specific instructions
So, I made following chagnes :
var markup = '<div id="ng-app" class="ng-app:myapp" ng-app="myapp" xmlns:ng="http://angularjs.org"><div ng-controller="MyAppAppCtrl"><div ng-view></div></div></div>';
jQuery('#works-modal').html(markup);
angular.bootstrap(jQuery('#ng-app'), ['myapp']);
jQuery('#works-modal').modal('show');
After implementing above changes, I was still getting :
Error: 10 $digest() iterations reached. Aborting!
https://github.com/angular/angular.js/issues/1417
While trying to render view, and application was redirecting to home page. so I tried making changes suggested in :
https://github.com/RobbinHabermehl/angular.js/commit/c801f91a25b9be6f5b1163c012e63c84cc6a1359
Now, I am no longer getting the error, when I click on link to display the Modal dialog, it displays the pop-up for a sec, then redirects to home page.
If I set :
$locationProvider.html5Mode(false)
.hashPrefix('!');
It works fine. Anyone facing similar issue? Any help is appreciated.
Update I've also reported this issue on Angular JS Github bug list, they informed me that they have fixed this issue on 1.2 version:
https://github.com/angular/angular.js/issues/3397
I'll check and update this thread if that resolves my problem.
Update
I updated my version of Angular, and this seems to resolve this "10 $digest() iterations reached. Aborting!", however, it still seems to be triggering URL change, leading it to redirect to home page.
Let me explain my scenario here, so that others can suggest me if this is exactly related to this or not:
I have a page say : http://example.com/users/myCollection.html On this page, I am loading my AngularJS App inside a Bootstrap Modal dialog, when user clicks some link, on page. Angular route of app loaded in Modal is : /mywork/find
After upping the version of Angular, now, Modal seems to loading the app for a second, then, redirect happens, and it goes to home page.
FYI, I am also using jQuery on the page that is used to launch the Angular App, is there any chance of conflict due to this?
Thanks, Ravish