Reputation: 11
I am trying to fetch queryParams from url with window.location but query params are not being grabbed.
Example my url is www.abc.com?accountId=123# I am looking for a way to grab accountId=123 as a queryParam or atleast the entire url.
When I used window.location I am getting www.abc.com/#/ instead of www.abc.com?accountId=123#
Why am I not able to read the query params?
Why am I not able to read the query params?
Upvotes: 1
Views: 66
Reputation: 298
according to the angular documentation you can fetch the query parameters with the activatedRoute in Angular.
In the below example we grab a query parameter "name".
constructor(
private route: ActivatedRoute,
) {}
ngOnInit() {
this.route.queryParams.subscribe(params => {
this.name = params['name'];
});
}
Upvotes: 1