Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Passing several parameters - object and values
Message
De
23/10/2014 07:22:49
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01609783
Message ID:
01609795
Vues:
43
>The code I showed was part of the service. At the top of the service we're declaring the functions and we're returning them and call them later in the controller.
>
>My question is how to pass multiple parameters to $http.get service where one parameter is an object and two other are string and boolean.

Ricks code show how to do it (wrap the parameters in a object using literal notation.....

>
>>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.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform