How to store add params in api url using angular js

Himanshu Bhuyan

my angular js function code

$scope.cardcall = function (cardtype) { 
        $scope.cityname=cityname;   
        $http({method: 'GET',url: '/api/v1/asasas&filterBy=cardNames&filterByValue='+cardtype.key}).success(function(data) {
            $scope.deal = data.deals;              
        });                  
    };

my view code

<div class="check_box" ng-repeat="cardtype in card.cardTypes.buckets">                                                  
 <label>
 <input type="checkbox" value=" {{cardtype.key}}" name="cardname" ng-click="cardcall(cardtype)" /> {{cardtype.key}} 
 </label>                                                   
</div>

now when some click on check box it call api like

/api/v1/asasas&filterBy=cardNames&filterByValue=asssas

What i am try to make when some one click 2nd check box then api call like

/api/v1/asasas&filterBy=cardNames&filterByValue=asssas,xsdza
DonovanM

You could add a .checked value to cardtype via ng-model

<input type="checkbox" ng-model="cardtype.checked" value=" {{cardtype.key}}" name="cardname" ng-change="typecall()" />

Then you could run a loop in your code to determine what's checked

$scope.cardcall = function () { 
    $scope.cityname=cityname;

    var keys = [],
        buckets = $scope.card.cardTypes.buckets;

    for (var i = 0, len = buckets.length, i < len; i++) {
        if (buckets[i].checked)
            keys.push(buckets[i].key);
    }

    if (keys.length) {
        keys = keys.join();

        $http({method: 'GET',url: '/api/v1/asasas&filterBy=cardNames&filterByValue=' + keys}).success(function(data) {
            $scope.deal = data.deals;              
        });
    }
};

This will be called every time one of those checkboxes gets checked or unchecked and since it looks through all of the checkboxes there's no need to pass cardtype.key anymore. If no checkboxes are checked it won't do an AJAX call.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to read all url params using js?

Angular 2: how to get params from URL without using Routing?

Apostrophecms : How to add url params in url by slashesh

Angular js - optional dynamic url params

Passing two params on angular js url using app states js and view

how to parse url add params in reactJs

How to include a param in browsers url when using params instead of url in angular ui routing?

How to store the root url of api in angular 4 app?

How to get the angular route params values in the url?

How to add input field validation for url using Angular.js/Javascript

Angular js - check if current url matches the route (with dynamic url params)

angular.js ui-route how catch route or url or params after reject?

How to query Facebook Graph API correctly in Google Apps Script using UrlFetchApp.fetch(url, params)?

How to get parameters using "/:params" in Angular 2

Next.js Add slug/params to clean URL

How to use a "complete Url" (url with params) for navigation in Angular

How can i pass additional params with each api call using Spine.js' Ajax Integration?

Get URL Params with JS

Pass params in google maps API url in vue.js

Get url params in API route handler in Next.js

Web Api 2 Attribute Routing and Angular JS params

Clean redirect from JS using Rails Turbolinks (with Url params)

Node.JS/Express - Get company products using URL params

How to create Singleton service in Angular 2 and read URL Params

How to get query params from url in Angular 2?

Angular2, how to clear URL query params on router navigate

how to pass URL path params to navitems in coreUI/angular sidebar

How to pass query params in url in a HTTP post request in Angular

Using react-redux with ajax call to API - How to store the API URL