Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tried to Load Angular More Than Once

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'); 
like image 419
Kyle Cureau Avatar asked Mar 23 '14 19:03

Kyle Cureau


2 Answers

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.

like image 159
Kyle Cureau Avatar answered Oct 18 '22 21:10

Kyle Cureau


The problem could occur when $templateCacheProvider is trying to resolve a template in the templateCache or through your project directory that does not exist

Example:

templateUrl: 'views/wrongPathToTemplate' 

Should be:

templateUrl: 'views/home.html' 
like image 32
grant Avatar answered Oct 18 '22 21:10

grant