Chapter 8: Using promises with $http

by msfrisbie

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('/')
      , b = a.success(function() {})
      , c = b.error(function() {})
      , d = c.then(function() {});
    
    $log.log(a===b, a===c, a===d, b===c, b===d, c===d);
    //       true   true   false  true   false  false
    
    var e = $http.get('/')
      , f = e.then(function() {})
      , g = e.then(function() {});
    
    $log.log(e===f, e===g, f===g);
    //       false  false  false
});