Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Passing several parameters - object and values
Message
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01609783
Message ID:
01609785
Vues:
54
This message has been marked as a message which has helped to the initial question of the thread.
What are you trying to do? The code you're doing isn't doing anything - you're creating an empty promise that will never complete.

All $http functions return a promise, so if you want to chain the callbacks and handle them in your controller just return the result from $http.get() etc.
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.

+++ Rick ---



>Hi everybody,
>
>I looked at this page
>
>https://docs.angularjs.org/api/ng/service/$http
>
>but it's still not clear to me.
>
>I have the following sample:
>
>
>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;
>        };
>
>Now, suppose I want to pass both to my getAccountInvoices - queryRequest object and two extra parameters (string and boolean). Should I just list them in the
>config object using this syntax:
>
>{ params: queryRequest, acctNameHash, showFinalized }
>
>?
>
>Thanks in advance.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform