Build query string from parameters object

前端 未结 4 1207
不知归路
不知归路 2020-12-05 03:54

How to build a url with query parameters in Angularjs.

I see the API $location.search()

the problem is $location(url) is to redirect to the url. In my case,

4条回答
  •  醉话见心
    2020-12-05 04:34

    Believe you really are sort of barking up the wrong tree... you need to take a look at $http service which gives you $http.get(url, config) or $http.post(url, data, config). For a GET request with parameters see the following SO

    $http get parameters does not work

    For information about $http and how it works see the Angular docs.

    http://docs.angularjs.org/api/ng.$http

    Perhaps I'm misunderstanding the goal though and you actually want to navigate to a different place, what I suggest here is just to make the request in the background (AJAX style).

    http://jsfiddle.net/4ZcUW/

    The JS

    angular.module("myApp", []).controller("MyCtrl", ["$scope", "$window", function($scope, $window) {
        $scope.goPlaces = function(url, parameter) {
            $window.open("http://www."+url+"?q="+parameter);
            //$window.open("http://www."+url+"?q="+parameter, "_self");
            //$window.open("http://www."+url+"?q="+parameter, "_top");
        };
    }])
    

    The HTML

    
    

    Does this work for your case?

提交回复
热议问题