Reputation: 731
I tried to access query params using below code.
let name : string = this.route.snapshot?.queryParams.name
console.log(name);
And I got the below error:
error TS1109: Expression expected
error TS1005: ':' expected
does not exist on type 'Params'.
How to resolve this issue.
Upvotes: 0
Views: 268
Reputation: 92
I think that your problem lies in the way you treat queryParams
.
It returns observable so you can change your code like that:
let name: string = '';
this.route.queryParams.subscribe(res => {
name = res.ResponseNameProperty;
console.log(name);
});
The res.ResponseNameProperty
is way how you get the name
property from revived object so you can first check how it looks using i.e. console.log(res)
and than use appropriate reference. I hope it fits your question and here you can found additional information about observables:
thoughtram
, official page, SO post
Upvotes: 1