Click here to see error message
错误$ injector:unpr未知提供商$ 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);
});
请帮助解决此错误
答案 0 :(得分:0)
你错过了一些注射:
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';
}]);
编辑(试试这个)
controller.js
var app = angular.module('advogeApp', ['ngCookies']);
也许它是最重要的模块?