Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  144] [ 5]  / answers: 1 / hits: 117587  / 10 Years ago, sun, march 23, 2014, 12:00:00

I have a yeoman scaffolded app (the angular fullstack generator).



grunt serve works fine, but grunt build produces a distribution that locks up memory, most probably because of circular references in angular.



I upgraded angular to 1.2.15. The error I get is:



WARNING: Tried to Load Angular More Than Once



Prior to upgrading, the error was:



Error: 10 $digest() iterations reached. Aborting!



It's pretty difficult to debug as it only happens after build / minification. All my modules are in angular's array format, so the minification DI shouldn't be a problem but it is.



There's no single script that causes this. The only way it goes away is if I don't initialize with my app.js file. My app.js file is below.



Any thing come to mind?



'use strict';

angular.module('myApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute',
'ngTagsInput',
'ui.bootstrap',
'google-maps',
'firebase'
]);

angular.module('myApp').config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/listing.html',
controller: 'ListingCtrl'
})
.otherwise({
redirectTo: '/'
});
}]).constant('FIREBASE_URL', 'something');

More From » angularjs

 Answers
13

This could be a number of issues: essentially it's a problem of routeProvider not finding a file and recursively loading the default.



For me, it turned out that it wasn't minification but concatenation of the js that caused the problems.



angular.module('myApp').config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/listing.html',
controller: 'ListingCtrl'
})
.otherwise({
redirectTo: '/'
});
}]).constant('FIREBASE_URL', 'something');


You'll notice that if the app can't find a file (i.e., otherwise), then it will redirect to the root, which in this case loads the templateUrl. But if your templateUrl is wrong, then it will cause a recursion that reloads index.html loading angular (and everything else) over and over.



In my case, grunt-concat caused the templateUrl to be wrong after build, but not before.


[#71830] Friday, March 21, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonmicahm

Total Points: 603
Total Questions: 120
Total Answers: 108

Location: Guam
Member since Fri, Jul 31, 2020
4 Years ago
;