$http.get with 2 parameter in ionic framework (angularjs)

All we need is an easy explanation of the problem, so here it is.

I have my $http.get with one parameter, and it works like :

getUserBand: function(email) {
        return $http.get(baseUrl + 'selectUserBand.php?email=' + email);
    },

I want to send 2 parameter like :

getUserBand: function(email,param2) {
        How to call 2 parameter in this field?
    },

How to call email and param2 in the $http.get field?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

You can append param with ‘&’:

getUserBand: function(email,param2) {    
  $http.get(baseUrl + 'selectUserBand.php?email=' + email + '&param2=' + param2);
}

Method 2

Store all your url params in an object like,

var urlParams = {
    'param1': email,
    'param2': username
},

now make the request using the following code,

$http({
    method: 'GET',
    url: 'url from which you want to get',
    params: urlParams //which will be automatically turned to ?key1=value1&key2=value2 after the url 
})

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply