简体   繁体   中英

How can I append key value pair to the url which already existed key value pair in AngularJS?

I have a click functions.In 1st click function i add the key value pair for existing url like this

$scope.OnItemClick = function (bedroom) {
    $location.path("/builders/"+r.id).search({bedrooms:bedroom});
}

so in remaining functions.I want to add extra key value pair based on existing url

$scope.range = function (range) {
    $location.path("/builders/"+r.id).search({budget:range});
}

$scope.status = function (status) {
    $location.path("/builders/"+r.id).search({status:status});
}

i tried to adding key value pair but its over riding each other like this.

1st click : ../#/builders/1?bedrooms=1
2nd click :../#/builders/1?budget:5(overriding)
3rd click :../#/builders/1?status:9(overriding)

so i want to do like this based on clicking functions:

../#/builders/1?budget=5&bedrooms=1&status=9
../#/builders/1?bedrooms=1&status=9&budget=5
../#/builders/1?bedrooms=1&budget=5&status=9

$location return search part of current URL.

You can do something like this:

$scope.range = function (range) {
    var current = $location.search();
    current.budget = range;
    $location.search(current);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM