0

点击这里查看错误信息

得到错误 $injector:unpr Unknown Provider for $cookies

我在我的 app.js 文件中添加了 ngcookies 模块,并在我的控制器中使用了 $cookie 服务,但是当我的控制器中注入 cookie 服务时,我无法创建 cookie 抛出错误

应用程序.js

angular.module('advogeApp', [
'ngResource',
'ngCookies',
'editorCtrl',
'SigninCtrl',
'SignupCtrl']).config(['$routeProvider', function($routeProvider, $httpProvider, $cookies){
    $httpProvider.defaults.xsrfCookieName = 'csrftoken';
    $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}]);

控制器.js

var app = angular.module('advogeApp');
app.controller('SigninCtrl', ['$scope', '$http', '$cookies', '$location', function($scope, $http, $cookies, $location) {$scope.loginData = function () {
            angular.element('#signin').modal("hide");
            $http({
                method : 'POST',
                url : '/proxy/',
                headers: {'Content-Type': 'application/json', 'endpoint' : '/login/'},
                data : JSON.stringify({email : $scope.userEmail, password : $scope.userPwd}),
            }).then(function(response){

                    $cookies.put('set-cookie', response.data.headers['set-cookie']);

                if (response.data.body.info == "sucessfully logged in") {
                            $location.path('/dashboard');
                     } else {
                            $scope.logininfo = response.data.info;
                            console.log(response.data);
                     }
            },function(response){
                console.log(response);
            });

请帮助解决这个错误

4

1 回答 1

0

您在这里错过了一些注射:

应用程序.js

angular.module('advogeApp', [
'ngResource',
'ngCookies',
'editorCtrl',
'SigninCtrl',
'SignupCtrl']).config(['$routeProvider','$httpProvider', '$cookies', function($routeProvider, $httpProvider, $cookies){
    $httpProvider.defaults.xsrfCookieName = 'csrftoken';
    $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}]);

编辑(试试这个)

控制器.js

var app = angular.module('advogeApp', ['ngCookies']);

也许它是压倒一切的模块?

于 2016-10-05T12:50:31.000 回答