注入Angular 1.4.7 cookie服务时出错

时间:2015-10-12 20:00:23

标签: angularjs cookies

我已经在网上对此进行过研究,但无法让它发挥作用。

我按照下面的在线文档将$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');
        };

    }
})();




我已将Angular从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>
&#13;
&#13;
&#13;

非常感谢建议...

鲍勃

1 个答案:

答案 0 :(得分: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'])