2016-12-02 64 views
0
var app = angular.module('mittens',['ui.router','ngCookies']); 

是不是上面正確的方法注入ngCookies?它拋出這個錯誤注入ngCookies時出錯?

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.9/ $injector/modulerr?p0=mittens&p1=Error%3A…0zc%20(http%3A%2F%2Flocalhost%3A3000%2Flibrary%2Fangular.min.js%3A20%3A274)(…) https://docs.angularjs.org/error/ $injector/modulerr?p0=mittens&p1=Error:%20%5B$injector:modulerr%5D%20http:%2F%2Ferrors.angularjs.org%2F1.4.9%2F$injector%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%2520g%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%2520g%2520(http%253A%252F%252Flocalhost%253A3000%252Flibrary%252Fangular.min.js%253A38%253A1)%0A%20%20%20%20at%20http:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:6:416%0A%20%20%20%20at%20http:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:38:427%0A%20%20%20%20at%20n%20(http:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:7:355)%0A%20%20%20%20at%20g%20(http:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:38:1)%0A%20%20%20%20at%20http:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:38:170%0A%20%20%20%20at%20n%20(http:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:7:355)%0A%20%20%20%20at%20g%20(http:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:38:1)%0A%20%20%20%20at%20db%20(http:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:41:272)%0A%20%20%20%20at%20c%20(http:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:19:463)%0A%20%20%20%20at%20zc%20(http:%2F%2Flocalhost:3000%2Flibrary%2Fangular.min.js:20:274

app.controller('HomeController',['$scope','$http','$cookies',function($scope,$http,$cookies) {} 
+0

我希望你有index.html中 –

回答

0

你在你的實際代碼拼寫錯誤ngCookiesngCookie但修正它的問題。

您是否點擊了公認的相當長的URL?

,將告訴你:

Failed to instantiate module mittens due to:

,然後又鏈接,告訴你:

Failed to instantiate module ngCookie due to:

,然後另一個鏈接帶您到:

Module 'ngCookie' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

每一種伴隨着一個堆棧跟蹤,但我在頂部引用的描述真的說了一切。 ngCookie不可用,因爲您忘記加載JavaScript或拼寫錯了名稱。

現在似乎有一些混淆,因爲你的問題說你要求'ngCookies',但是錯誤消息說沒有找到'ngCookie'。檢查您發佈問題時是否未自動更正名稱的拼寫錯誤。

+0

inclded ngCookie當我排除「ngCookies」的依賴並加載程序然後角cookie.js也增加了給我的錯誤的依賴後working.Only – chyangba

+0

你是積極的,你在你的程序中寫了'ngCookies'?錯誤頁面的鏈接說你使用了'ngCookie'。 – Duncan

+0

我正在使用ngCookies.'angular.module('app',['ui.router','ngCookies']); – chyangba

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

+0

[JSFIDDLE鏈接](https://jsfiddle.net/ycczfskb/) – chyangba

+0

它應該是var app = angular.module('mittens',['ui.router','ngCookies']) – Sajeetharan

0

因爲你忘了加載角的cookies文件。首先加載th文件,然後嘗試。

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

有了,你已經準備好開始!

+0

[JSFIDDLE link]( https://jsfiddle.net/ycczfskb/) – chyangba