I'm using PhpStorm to develop an Angular app and I have an "unresolved variable" error at
params.myid
Here is the code line:
this.route.params.subscribe((params: Params) => {
const avalancheid = params.myid;
});
There is no error if I change the type to "any" instead of "Params"
this.route.params.subscribe((params: any) => {
const avalancheid = params.myid;
});
Angular version: 4.2.4, PhpStorm version: 2017.2.4
That's because your Params
class doesn't contain the key myid
, by using square brackets params['myid']
you should be able to get the value as shown in the docs.
The reason it's crashing is because you're telling the TypeScript compiler "Hey, I'm expecting Params
", at which point you then proceed to tell it to get a property named myid
which the original Params
class doesn't contain, hence the error.