【发布时间】:2018-07-19 02:07:58
【问题描述】:
您好,我尝试在网络响应后保存在 cookie 中。这是我的代码
angular.module('myApp').controller('SignInController',['WebService',function(WebService, $cookies){
this.formData = {};
this.signIn = function(formData){
WebService.login(formData).then(function successCallback(data){
//console.log("Success callback:"+JSON.stringify(data));
var response = data.data;
var message = response['message'];
if (message == 'Success') {
$cookies.put("id", response['id']);
$cookies.put("number", response['number']);
}else{
}
console.log('Message:'+message+" id:"+ $cookies.get('id'));
},function errorCallback(error){
console.log("Error"+JSON.stringify(error));
});
this.formData = {};
};
}]);
我在创建主要 Angular 模块时将 ngCookies 作为模块包含在内。我在这里做错了什么?任何人都告诉我正确的方法。谢谢。
【问题讨论】:
-
修复您的注射:
['WebService', '$cookies',function(WebService, $cookies) -
,['WebService',function(WebService, $cookies) - 在 'Webservice' 之后添加 '$cookies' 怎么样?
-
谢谢你 Aleksey Solovey :)