ThomasBurleson
8/19/2013 - 1:03 PM

Using AngularJS $http: the WRONG way.

Using AngularJS $http: the WRONG way.

/**
 * Register factory for `stockService` instances. 
 * 
 * Note: the getStocks() expects a callback function used to notify 
 *       the caller when the data is ready.
 * 
 *       !! This is BAD !!
 */
angular.factory('stockService', function($http) 
{
  return {
    getStocks: function(callback) 
    {      
       $http
           .get('stocks.json')
           .success( function(data) 
           { 
               // initiating callback with data
               callback(data);             
           });
    };
  };
};