function callService(parm1,parm2) { return $http.get('service/endpoint',{p1: parm1, p2: parm2}) .success(function() { console.log('initial success"); }) .error(function() { showError('failed"); }); }Then the caller can do:
callService(parm1,parm2) .success(function() { alert('made it!' });This is the way to delegate responsibility and have multiple intercept points for results returned from async operations. This is a common pattern if you use a service.
>var getAccounts = function(queryRequest) { > var deferred = $q.defer(); > $http.get('/api/accounts', { params: queryRequest }) > .success(function(data) { > deferred.resolve(data); > }) > .error(function(data, status, header, config) { > deferred.reject(status); > }); > return deferred.promise; > }; > > var getAccountInvoices = function (acctNameHash, showFinalized) { > var deferred = $q.defer(); > $http.get('/api/accounts/getAccountInvoices/' + acctNameHash + '/' + showFinalized) > .success(function (data) { > deferred.resolve(data); > }) > .error(function (data, status, header, config) { > deferred.reject(status); > }); > return deferred.promise; > };>
>{ params: queryRequest, acctNameHash, showFinalized }>