Suppose the data returned from applicationsService using the async method:
var data = [ { "PreAlertInventory": "5.000000", "SharesInInventory": "3.000000", "TotalSharesSold": "2.000000" }
and applicationsService factory returns a promise:
.factory('applicationsService', ['$resource','$q', function($resource, $q) { var data = [ { "PreAlertInventory": "5.000000", "SharesInInventory": "3.000000", "TotalSharesSold": "2.000000" } ]; var factory = { getCurrentApp: function () { var deferred = $q.defer(); deferred.resolve(data); return deferred.promise; } } return factory; }]);
I would just call api.tickets()
$scope.data = api.tickets();
but our api service will look like this:
.factory('api', function($resource, applicationsService,$q, $timeout) { function fetchAppId() { return applicationsService.getCurrentApp(); } return { tickets: function() { var deferred=$q.defer(); fetchAppId().then(function(data) {
Fiddle Demo
source share