angular ng-strict-di不适用于ngRoute

时间:2015-04-17 13:41:33

标签: angularjs ngroute angularjs-ng-route

如果我将ng-strict-di用于我的Angular应用,并使用ngRoute模块,则会收到错误消息:

[Error] Error: [$injector:modulerr] http://errors.angularjs.org/1.4.0-rc.0/$injector/modulerr?p0=epoiApp&p1=%5B%24injector%3Astrictdi%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.4.0-rc.0%2F%24injector%2Fstrictdi%3Fp0%3Dfunction(%2524routeProvider)%0Ahttps%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A6%3A426%0A%24%24annotate%40https%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A182%3A482%0Ae%40https%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A37%3A533%0Ad%40https%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A36%3A238%0Ahttps%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A36%3A358%0An%40https%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A7%3A306%0Ah%40https%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A36%3A135%0A%24a%40https%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A39%3A417%0Ad%40https%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A18%3A383%0Auc%40https%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A19%3A180%0AUd%40https%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A18%3A2%0Ahttps%3A%2F%2Fcode.angularjs.org%2F1.4.0-rc.0%2Fangular.min.js%3A285%3A431%0Afire%40file%3A%2F%2F%2FVolumes%2FMacintosh%2520HD%2FUsers%2FdeLac%2Fsiti%2Fepoi%2FePOI%2Fassets%2Flibs%2Fjquery.js%3A3143%3A35%0AfireWith%40file%3A%2F%2F%2FVolumes%2FMacintosh%2520HD%2FUsers%2FdeLac%2Fsiti%2Fepoi%2FePOI%2Fassets%2Flibs%2Fjquery.js%3A3255%3A11%0Aready%40file%3A%2F%2F%2FVolumes%2FMacintosh%2520HD%2FUsers%2FdeLac%2Fsiti%2Fepoi%2FePOI%2Fassets%2Flibs%2Fjquery.js%3A3467%3A24%0Acompleted%40file%3A%2F%2F%2FVolumes%2FMacintosh%2520HD%2FUsers%2FdeLac%2Fsiti%2Fepoi%2FePOI%2Fassets%2Flibs%2Fjquery.js%3A3498%3A15
    (anonymous function) (angular.min.js, line 37)
    n (angular.min.js, line 7)
    h (angular.min.js, line 36)
    $a (angular.min.js, line 39)
    d (angular.min.js, line 18)
    uc (angular.min.js, line 19)
    Ud (angular.min.js, line 18)
    (anonymous function) (angular.min.js, line 285)
    fire (jquery.js, line 3143)
    fireWith (jquery.js, line 3255)
    ready (jquery.js, line 3467)
    completed (jquery.js, line 3498)

这对我来说很奇怪,因为ngRoute是Angular的官方模块,不是吗?还有办法一起使用它们吗?

我已经包含了angular-route.min.js

<script src="https://code.angularjs.org/1.4.0-rc.0/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0-rc.0/angular-route.min.js"></script> 

2 个答案:

答案 0 :(得分:0)

注册申请时必须注入此模块。

它没有附带angular.js文件。 ngRoute angular-route.js 文件中定义

angular.module('app', ['ngRoute']);

为此,您必须先加载angular-route.js

angular-route.js

答案 1 :(得分:0)

pasted the error并获得了确切的错误文字

  

由于以下原因无法实例化模块epoiApp:[$ injector:strictdi]   http:// errors.angularjs.org/1.4.0-rc.0/$injector/strictdi ...)   https:// code.angularjs.org/1.4.0-rc.0/angular.min.js:6:426

您应该包含缩小版本的ng-route(angular-route.min.js)以避免此错误。

有许多方法可以使代码缩小安全,你使用strict-di,ng-route可能正在使用ng-annotate。每个库开发人员可能使用不同的方法来使代码缩小安全。最终目标应该是实现非破坏性缩小代码。