As suggested above:
promise.then(function(value) {
// Value contains the data received in the response
}, function(error) {
// This is called when error occurs.
}
)
The promise itself does not contain a value. It returns the value in the future ("promises" to return a value) when it's available. And when it becomes available (or not), one of two callbacks passed to then() methods gets triggered.
So basically, you should make calls like this:
$http.get('/api/random').then(function(response) {
// Do some stuff with response.
});
You can pass a callback to finally() method callback, which will be run regardless of success or error in promise.
$http.get('/api/random').then(function(response) {
// This one is triggered in case of successful response.
}, function(error) {
// This code runs in case of error
}).finally(function() {
// And this block will be triggered anyway after the promise returns.
});
promise.then(function(value) { acessValueHere(value); }), as for all promises. Read blog.ninja-squad.com/2015/05/28/angularjs-promises