var app = angular.module('mittens',['ui.router','ngCookies']);
不是正确的注入ngCookies的方法吗?它抛出了这个错误
未捕获错误:[$ injector:modulerr] http://errors.angularjs.org/1.4.9/ $注射器/ modulerr P0 =手套&安培; P1 =错误%3A ... 0zc%20(HTTP%3A%2F%2Flocalhost%3A3000%2Flibrary%2Fangular.min.js%3A20%3A274)(...) https://docs.angularjs.org/error/ $注射器/ modulerr P0 =手套&安培; P1 =错误:%20%$ 5B注射器:modulerr%5D%20http:%2F%2Ferrors.angularjs.org%2F1.4.9%2F $注射器%2Fmodulerr% 3Fp0%3DngCookie%26P1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.4.9%252F%2524injector%252Fnomod%253Fp0%253DngCookie%250A%2520% 2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A3000%252Flibrary%252Fangular.min.js%253A6%253A416%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A3000%252Flibrary% 252Fangular.min.js%253A24%253A186%250A%2520%2520%2520%2520at%2520B%2520(HTTP%253A%252F%252Flocalhost%253A3000%252Flibrary%252Fangular.min.js%253A23%253A252)%250A%2520 %2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A3000%252Flibrary%252Fangular.min.js%253A23%253A495%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A3000%252Flibrary %252Fangular.min.js%253A38%253A153%250A%2520%2520%2520%2520at%2520n%2520(HTTP%253A%252F%252Flocalhost%253A3000%252Flibrary%252Fangular.min .js文件%253A7%253A355)%250A%2520%2520%2520%2520at%2520克%2520(HTTP%253A%252F%252Flocalhost%253A3000%252Flibrary%252Fangular.min.js%253A38%253A1)%250A%2520%2520 %2520%2520at%2520http%253A%252F%252Flocalhost%253A3000%252Flibrary%252Fangular.min.js%253A38%253A170%250A%2520%2520%2520%2520at%2520n%2520(HTTP%253A%252F%252Flocalhost%253A3000 %252Flibrary%252Fangular.min.js%253A7%253A355)%250A%2520%2520%2520%2520at%2520克%2520(HTTP%253A%252F%252Flocalhost%253A3000%252Flibrary%252Fangular.min.js%253A38%253A1) %0A%20%20%20%20原子%20http:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:6:416%0A%20%20%20%20原子%20http:%2F%2Flocalhost:3000 %2Flibrary%2Fangular.min.js:38:427%0A%20%20%20%20原子%20N%20(HTTP:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:7:355)%0A %20%20%20%20原子%20克%20(HTTP:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:38:1)%0A%20%20%20%20原子%20http:%2F% 2Flocalhost:3000%2Flibrary%2Fangular.min.js:38:170%0A%20%20%20%20原子%20N%20(HTTP:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:7:355 )%0A%20%20%20%20A吨%20克%20(HTTP:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:38:1)%0A%20%20%20%20原子%20分贝%20(HTTP:%2F%2Flocalhost:3000 %2Flibrary%2Fangular.min.js:41:272)%0A%20%20%20%20原子%20C%20(HTTP:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:19:463)% 0A%20%20%20%20原子%20zc%20(HTTP:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:20:274
app.controller('HomeController',['$scope','$http','$cookies',function($scope,$http,$cookies) {}
答案 0 :(得分:1)
您在实际代码中将ngCookies
拼错为ngCookie
,但针对该问题进行了更正。
您是否点击了相当长的网址?
那会告诉你:
由于以下原因导致无法实例化模块手套:
然后另一个链接告诉你:
由于以下原因无法实例化模块ngCookie:
然后是另一个链接,它将您带到:
模块'ngCookie'不可用!你要么拼错了模块 命名或忘记加载它。如果注册模块,请确保您 将依赖项指定为第二个参数。
每个都伴随着堆栈跟踪,但我在顶部引用的描述确实说明了一切。 ngCookie
不可用,因为您忘记加载JavaScript或拼错了它的名字。
现在似乎有一些混乱,因为您的问题是您要求'ngCookies'
,但错误消息显示'ngCookie'
未找到。发布问题时,请检查您是否未自动更正名称拼写错误。
答案 1 :(得分:0)
确保您有参考图书馆
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-cookies.js" type="text/javascript"></script>
起诉你已经注入了依赖
var miAp = angular.module('miAp', ['ngCookies']);
<强> DEMO 强>
答案 2 :(得分:0)
因为您忘记加载角度Cookie文件。首先加载文件,然后尝试。
<script src="path/to/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-cookie/4.0.0/angular-cookie.js"></script>
最后,通过将模块添加为依赖模块来加载应用程序中的模块:
angular.module('app', ['ngCookies']);
有了这个,你就可以开始了!