Created
November 30, 2013 04:06
-
-
Save wesleycho/7715229 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory('api', ['$http', '$q', '$log', function($http, $q, $log) { | |
return { | |
last: function(market, currency){ | |
$log.log('api/last', currency, 'market', market); | |
//return the promise directly. | |
return $http.get('/api/last/'+market+'/'+currency) | |
.then(function(result) { | |
//resolve the promise as the data | |
$log.log('api.last data', result.data); | |
return result.data; | |
}); | |
} | |
, exchanges: function(){ | |
//return the promise directly. | |
var deferred = $q.defer(); | |
$http.get('/api/exchanges') | |
.success(function (data) { | |
deferred.resolve(data); | |
}); | |
return deferred.promise; | |
} | |
}; | |
}]); | |
// in OrderCtrl | |
exchanges.then(function (data) { | |
$scope.exchanges = data; | |
}); | |
// or... | |
resolve: { | |
exchanges: function ($q, api) { | |
var deferred = $q.defer(); | |
api.exchange().then(function (data) { | |
deferred.resolve(data.data.exchanges); | |
}); | |
return deferred.promise; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment