Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Angular $location service support multiple parameters?

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&param2=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!

like image 554
jedd.ahyoung Avatar asked May 13 '13 07:05

jedd.ahyoung


People also ask

What is the purpose of $location service in AngularJS?

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.

Which method of $location service is used to get the full URL of the current web page?

absUrl(); This method is getter only. Return full URL representation with all segments encoded according to rules specified in RFC 3986.

What does location Search do?

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.

What is location path?

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.


1 Answers

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?

like image 53
Narretz Avatar answered Nov 01 '22 05:11

Narretz