由于以下原因无法实例化模块indexModule:错误:[$ injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0 = n ...)

时间:2015-11-10 17:04:01

标签: angularjs

我正在尝试在我的项目中使用ngCookies,但每当我尝试注入时,我都会在标题中出现错误。

HTML:

    <script src ="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.min.js" type="text/javascript"></script>

//where I believe the issue is happening
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-cookie/4.0.9/angular-cookie.min.js" type="text/javascript"></script>



 <script src ="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular-route.min.js" type="text/javascript"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.4/ui-bootstrap-tpls.min.js"></script>

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.css">

角:

angular.module("indexModule", ["ngRoute", "ngCookies", "ui.bootstrap"]);

我尝试使用Angular文档中提供的CDN,但是我得到了同样的错误。

1 个答案:

答案 0 :(得分:1)

您的问题出在angular-cookie.min.js。您提供的链接无效。我试过没有任何错误。见demo

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular-cookies.js" type="text/javascript"></script>

根据您的代码,angular无法在ngCookies中注入indexModule。因此需要更改angular-cookies.js的cdn。

<script src ="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.min.js" type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular-cookies.js" type="text/javascript"></script>
<script src ="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular-route.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.4/ui-bootstrap-tpls.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.css">