How to implement passing of variable from one service method to another
angular
Hi to all angular guru,
My question is how to pass the return result of one service method to the
other methods. Or to make it short I have an authentication method in my
service, the return object result for this is a token. The token will be
used to be append in my header for the rest of my http request which
reside on the same service.
E.g
my Service js
authenticatePlayer: function(postData) {
return $http({
method : 'POST',
url : api + 'auth/player',
data : postData,
headers : {'Content-Type' : 'application/json'}
})
.then(function(result) {
return result.data.token; //this is now the token
}, function (result) {
console.log(result);
});
}
within the Service js, I have other $http request such as:
getPlayerByEmail: function(email_address) {
return $http({
method : 'GET',
url : api + 'player/' + email_address,
headers : {'X-token': token}
//token here is from the authenticatePlayer method but how to
get it??
})
.then(function(result) {
return result.data;
});
}
The two services methods are called in two controllers, my extended
question is how to you pass the $scope from one controller to another that
even when the page is refreshed the $scope value won't be destroy.
Hope it make sense.
No comments:
Post a Comment