2015-10-12 82 views
2

我已經在線調查過這些信息,但無法使其正常工作。注入Angular 1.4.7 Cookie服務時出錯

我跟着這個在線文檔下方注入$cookies服務爲我登錄控制器,但我不斷收到錯誤:[$injector:modulerr]

cookie injection

(function() { 
 
    'use strict'; 
 

 
    angular.module('rage', ['ngCookies']).controller('LoginCtrl', 
 
     ['$rootScope', '$scope', '$cookies', '$modalInstance', '$q', 'datacontext', 'userService', authenticate]); 
 

 
    function authenticate($rootScope, $scope, $cookies, $modalInstance, $q, datacontext, userService) { 
 

 
     var login = this; 
 

 
     // OK,CANCEL CLICK EVENTS FROM MODAL !!! 
 
     $scope.ok = function() { 
 
         
 
      var user = {userId: login.userId, pswd: login.pswd}; 
 
      $modalInstance.close(user); 
 
     }; 
 
     $scope.cancel = function() { 
 
      $modalInstance.dismiss('cancel'); 
 
     }; 
 

 
    } 
 
})();

我已經升級角從1.3.5到1.4.7,我的index.html有:

<!-- jQuery and Bootstrap -->  
 
<script src="Scripts/jquery/jquery.min.js"></script> 
 

 
<script src="Scripts/plugins/jquery-ui/jquery-ui.min.js"></script> 
 
<script src="Scripts/bootstrap/bootstrap.min.js"></script> 
 

 
<!-- Angular scripts--> 
 
<!--<script src="Scripts/angular/angular-1.3.5.min.js"></script>--> 
 
<script src="Scripts/angular/angular-1.4.7.min.js"></script> 
 
<script src="Scripts/angular/angular-sanitize.min.js"></script> 
 
<script src="Scripts/angular-ui-router/angular-ui-router.min.js"></script> 
 
<script src="Scripts/angular/angular-cookies-1.4.7.min.js"></script> 
 

 
<!-- angular-ui-bootstrap --> 
 
<!--<script src="Scripts/bootstrap/ui-bootstrap-tpls-0.11.0.min.js"></script>--> 
 
<script src="Scripts/bootstrap/ui-bootstrap-tpls-0.13.0.min.js"></script>

建議是極大的讚賞...

鮑勃

回答

2

ngCookies外部模塊:你必須包括在指數angular-cookie.js腳本。

除此之外,我看到你注入了$modalInstance,這可能是ui-bootstrap的服務。您還必須包含angular-ui-bootstrap腳本,並將該模塊作爲依賴項添加。

綜上所述,您的index.html應該是這樣的:

<script src="scripts/.../angular.js"></script> 
<script src="scripts/.../angular-cookie.js"></script> 
<script src="scripts/.../ui-bootstrap-tpls.js"></script> 

和模塊聲明:

angular.module('rage', ['ngCookies', 'ui.bootstrap']) 
+0

是真的!我從字面上只是發現了這一點,並下載了angular-cookies.js版本1.4.7,以便與Angular 1.4.7一致。儘管如此,我仍然試圖擺脫一些錯誤。 –

+0

我想設置一個cookie過期,看來版本1.4.7有它,但沒有例子 - 即https://code.angularjs.org/1.4.7/docs/api/ngCookies/provider/ $ cookiesProvider。有任何想法嗎 ? –

+0

var expireDate = expireDate = moment()。add(3,「month」).format(); $ cookie.put(「cookieName」,cookieString,{'expires':expireDate}); –