javascript - TypeError: Cannot read property '$cookies' of undefined -
i'm trying save response server cookies, , here how i'm trying do
this.$http({ method: 'post', url: some_url, data: some_data, headers: { 'authorization': this.basicauthorization } }).success(function(data){ //console.log(data); this.$cookies.putobject('userdata', data); }).error(function(data){ }); }
i provided:
angular.module('mymodule', [ ...., 'ngcookies' ]) // ........ loginhandler.$inject = ['$http', '$cookies']; // ........ constructor($http, $cookies){ ... }
what causing error? i'm using angularjs 1.4.0
update
i have found out this
not working expected in .success() etc. had store in other variable.
try this,
var self = this; this.$http({ method: 'post', url: some_url, data: some_data, headers: { 'authorization': this.basicauthorization } }).success(function(data){ //console.log(data); self.$cookies.putobject('userdata', data); }).error(function(data){ }); }
Comments
Post a Comment