I'm just trying to use $location.path()
in my controller but also passing a custom variable as a parameter. So it would look something like this I guess:
$scope.parameter = 'Foo'; $location.path('/myURL/' + $scope.parameter);
But that doesn't work. Anyone know how this is supposed to be done in Angular?
absUrl(); This method is getter only. Return full URL representation with all segments encoded according to rules specified in RFC 3986.
HTML. Output: search() Method: It is a read and writes method of $location. It returns the current search parameters of the URL when passed without parameters and when passed with parameters it returns the $location object.
In HTML5 mode, the $location service getters and setters interact with the browser URL address through the HTML5 history API. This allows for use of regular URL path and search segments, instead of their hashbang equivalents.
Location is a service available in Angular 2+ apps that makes it easy to interact with the current URL path. For most navigation needs, the Angular router is the correct solution, but in a few cases the location service is needed to affect the url without involving the router.
to add Parameters you should use $location.search()
method so:
$location.path('/myURL/').search({param: 'value'});
$location
methods are chainable.
this produce :
/myURL/?param=value
The another way to add parameter to url is:
$location.path('/myURL/'+ param1);
and you can define route to myPage.html:
config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/myURL/:param1', { templateUrl: 'path/myPage.html', controller: newController }); }]);
The parameter can then be accessed in newController as follows:
var param1= $routeParams.param1;
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