I am having trouble with binding this
inside a promise. I have the following function in angular service:
this.database_view_settings = {'habal':'1'}
this.init = function(){
console.log("1",this.database_view_settings)
return $q((resolve, reject) => {
console.log("2",this.database_view_settings)
AuthenticationService.getToken().then(function(token){
$http.get('/api/user/settings/database_view/get',{headers:{'id_token':token}})
.success(function(data) {
console.log("3",this.database_view_settings)
this.database_view_settings = data;
console.log("login",this.database_view_settings)
resolve(this.database_view_settings)
})
.error(function(data) {
console.log('Error: ' + data);
reject(data)
});
}.bind(this))
})
}.bind(this)
My problem is that while at console.log 1 and 2
I see what I want to {'habal':'1'}
at console.log 3
I get an undefined
and I don't understand why.