Chapter 8: Using promises with $http
HTML
<script src="https://code.angularjs.org/1.3.2/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="Ctrl"></div>
</div>
JavaScript
angular.module('myApp', [])
.controller('Ctrl', function ($log, $http) {
// these are split into variables to be able to inspect
// the returned promises
var a = $http.get('/echo/json')
, b = a.success(function() {})
, c = b.error(function() {})
, d = c.then(function() {});
$log.log('State:' + a.$$state.status);
$log.log(a===b, a===c, a===d, b===c, b===d, c===d);
// true true false true false false
if (a.$$state.status === 0) {
$log.log(a.$$state.status)
} else if (a.$$state.status === 1) {
$log.log(a.$$state.status)
} else if (a.$$state.status === 0) {
$log.log(a.$$state.status)
}
});