Tried to Load Angular More Than Once

2020-01-24 04:05发布

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');

22条回答
Lonely孤独者°
2楼-- · 2020-01-24 04:49

In my case I was getting this error while using jquery as well as angular js on the page.

<script src="http://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="js/angular.js" type="text/javascript"></script>
<script src="js/angular-route.js" type="text/javascript"></script>

I removed :

<script src="http://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>

And the warning disappeared.

查看更多
爷的心禁止访问
3楼-- · 2020-01-24 04:54

I had the same issue, The problem was the conflict between JQuery and Angular. Angular couldn't set the full JQuery library for itself. As JQLite is enough in most cases, I included Angular first in my web page and then I loaded Jquery. The error was gone then.

查看更多
倾城 Initia
4楼-- · 2020-01-24 04:57

I had this same problem ("Tried to Load Angular More Than Once") because I had included twice angularJs file (without perceive) in my index.html.

<script src="angular.js">
<script src="angular.min.js">
查看更多
我想做一个坏孩纸
5楼-- · 2020-01-24 04:57

I have the same problem, because I have angular two times in index.html:

<script src="https://handsontable.github.io/ngHandsontable/node_modules/angular/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

Note that the warning arises only when html5 mode is true, when my html5 mode was false, I did not see this warning.

So removing the first angular.js solves the problem.

查看更多
【Aperson】
6楼-- · 2020-01-24 04:57

I had this problem when missing a closing tag in the html.

enter image description here

So instead of:

<table></table> 

..my HTML was

<table>...<table>

Tried to load jQuery after angular as mentioned above. This prevented the error message, but didn't really fix the problem. And jQuery '.find' didn't really work afterwards..

Solution was to fix the missing closing tag.

查看更多
Animai°情兽
7楼-- · 2020-01-24 04:58

Seems like nobody has mentioned this anywhere so here is what triggered it for me: I had the ng-view directive on my body. Changing it like so

<body layout="column">
<div ng-view></div>
...
</body>

stopped the error.

查看更多
登录 后发表回答