I thought using getAll
with a paramMap
could help with getting arrays from the URL but apparently not.
Am I using it wrong?
Here's an example : https://stackblitz.com/edit/angular-bjrjz9
I navigate with this
this.router.navigate(['two', {
id: [1, 2, 3, 4, 5]
}]);
And then I get the values
this.route.paramMap.subscribe(params => {
const ids = params.getAll('id');
console.log('ids', ids);
});
console.log says ['1,2,3,4,5']
but I expected it to be [1,2,3,4,5]
or even ['1', '2', '3', '4', '5']
I'm just trying to pass an array to a route and then get the array back at the destination.
Of course, I could just split the string but what's the point of having getAll
in that case? :)
Angular 2 applications require to redirect route and pathMatch is a property which informs a router how to match and map a URL to the path of an actual route. In the application, the router automatically select the route using component HeroListComponent only when the entire URL of matches for example-
redirectTo: '/home': We are using this property within the routes array to tell angular route service if the users navigate to the empty URL they should be redirected to the home URL rather than the empty URL.
The getAll()
method returns duplicate parameters as an array.
Example:
http://www.example.com/?query=a&query=b&query=c
The value would be:
console.log(params.getAll('query')); // prints ["a","b","c"]
All query parameters in the HTTP specification are strings.
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