Using Angular's $location.search()
method, it is possible to create a URL parameter, like this:
http://mysite.com/page?param=myParam
Is it possible to create multiple URL parameters, like this?
http://mysite.com/page?param=myParam¶m2=myParam2&...
I've tried adding multiple object parameters to the function call (ex. $location.search({ key1: value, key2: value })
), but I'm only receiving one key/value in the URL.
Thanks!
The $location in AngularJS basically uses a window. location service. The $location is used to read or change the URL in the browser and it is used to reflect that URL on our page. Any change made in the URL is stored in the $location service in AngularJS.
absUrl(); This method is getter only. Return full URL representation with all segments encoded according to rules specified in RFC 3986.
location.search returns the query portion of a URL including the Question mark (?). This return a string and then we do substring operation on that string. substring(1) means return the string skipping the first character.
pathname. The pathname property of the Location interface is a string containing the path of the URL for the location. If there is no path, pathname will be empty: otherwise, pathname contains an initial '/' followed by the path of the URL, not including the query string or fragment.
It does work in this fiddle: http://jsfiddle.net/PHnLb/42/
$scope.changeTarget = function(name) {
$location.search({target : 'Hi', new : 'else'});
}
(Angular 1.1.4, HTML5 mode = true)
Which version of angular are you using?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With