尝试多次加载 Angular [英] Tried to Load Angular More Than Once
问题描述
我有一个自耕农脚手架应用程序(角度全栈生成器).
I have a yeoman scaffolded app (the angular fullstack generator).
grunt serve
工作正常,但是 grunt build
产生一个锁定内存的分布,很可能是因为 angular 中的循环引用.
grunt serve
works fine, but grunt build
produces a distribution that locks up memory, most probably because of circular references in angular.
我将 angular 升级到 1.2.15
.我得到的错误是:
I upgraded angular to 1.2.15
. The error I get is:
警告:尝试多次加载 Angular
在升级之前,错误是:
错误:已达到 10 次 $digest() 迭代.中止!
调试非常困难,因为它只发生在构建/缩小之后.我所有的模块都是 angular 的数组格式,所以缩小 DI 不应该是一个问题,但它是.
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.
没有单一的脚本会导致这种情况.它消失的唯一方法是我不使用我的 app.js 文件进行初始化.我的 app.js 文件在下面.
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.
想到什么了吗?
'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');
推荐答案
这可能有很多问题:本质上是 routeProvider 找不到文件并递归加载默认文件的问题.
This could be a number of issues: essentially it's a problem of routeProvider not finding a file and recursively loading the default.
对我来说,结果不是缩小,而是 js 的串联导致了问题.
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');
您会注意到,如果应用程序找不到文件(即 otherwise
),它将重定向到根目录,在这种情况下会加载 templateUrl代码>.但是如果您的
templateUrl
是错误的,那么它会导致递归重新加载 index.html
加载 angular(以及其他所有内容)一遍又一遍.
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.
就我而言,grunt-concat 导致 templateUrl 在构建之后出错,但之前没有.
In my case, grunt-concat caused the templateUrl to be wrong after build, but not before.
这篇关于尝试多次加载 Angular的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!