praveen
praveen

Reputation: 485

Getting error while trying to use paramMap for getting 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 following error

paramMap doesn't exist on type 'ActivatedRoute'

Upvotes: 3

Views: 3954

Answers (5)

Ashok Seshan
Ashok Seshan

Reputation: 1

ParamMap has been introduced in 4.0.0-rc.6 version. Make sure you have at-least Angular 4 version.

Upvotes: 0

Stephen R. Smith
Stephen R. Smith

Reputation: 3400

Make sure you're importing ParamMap from @angular/router

import { Router, ActivatedRoute, ParamMap } from '@angular/router';

Upvotes: 0

codeExcalibur
codeExcalibur

Reputation: 23

import 'rxjs/add/operator/switchMap';

add that import to your component...

Upvotes: 1

eugeneoei
eugeneoei

Reputation: 210

not too sure if this will help but you may want to try following:

  1. delete the node_modules folder in your project
  2. in your package.json file, check that your @angular/router dependency is of angular 4 version (ie 4.0.0 and up)
  3. 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 at which version and up that is. to be on the safe side, you may want to just update your rxjs to the latest version as well)
  4. finally npm install

hopefully this works for you. i had the same issue and if i never remember wrongly, i did the above and ParamMap exist after.

Upvotes: 0

Vamshi
Vamshi

Reputation: 9341

In your switchmap paramMap type is wrong.

It should be

.switchMap((params : ParamMap) => 

Upvotes: 0

Related Questions