Getting error when trying to use paramMap to get route parameters
export class HeroDetailComponent {
heroes;
constructor(private route: ActivatedRoute, private router: Router, private hs : HeroService){
}
ngOnInit(){
this.route.paramMap
.switchMap((params : ParamMap) =>
this.hs.getHeroes(params.get('id')))
.subscribe((heroes) => {
console.log("checking for heroes n subscribe",heroes);
this.heroes = heroes})
}
}
Getting next error
paramMap does not exist in type "ActivatedRoute"
+3
source to share
5 answers
not too sure if this helps, but you can try this:
- delete the node_modules folder in your project
- in your package.json file make sure your @ angular / router dependency is from angular 4 version (i.e. 4.0.0 and up)
- make sure your typescript version is at least 2.1.6 in both "dependencies" and "devDependencies" in your package. json (some versions of typescript and up breaks rxjs. I'm not too sure if the versions are higher, that is, to be safe, you can just update your rxjs to the latest version).
- finally install npm
hope this works for you. I had the same problem and if I'm never wrong I did the above and ParamMap exists after.
0
source to share