点击这里查看错误信息
得到错误$injector:unpr Unknown Provider for $cookies
我在我的app.js文件中添加了ngcookies模块,并在我的控制器中使用了$cookie服务,但是我不能创建一个cookie当cookie服务注入到我的控制器
时抛出错误app.js
angular.module('advogeApp', [
'ngResource',
'ngCookies',
'editorCtrl',
'SigninCtrl',
'SignupCtrl']).config(['$routeProvider', function($routeProvider, $httpProvider, $cookies){
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}]);
controller.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);
});
请帮忙解决这个错误
您这里漏打了几针:
app.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';
}]);
EDIT (try this)
controller.js
var app = angular.module('advogeApp', ['ngCookies']);