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})
    }

}

获取跟踪错误
parammap在类型“activatedroute”上不存在

最佳答案

import 'rxjs/add/operator/switchMap';
将导入添加到组件…

关于angular - 尝试使用paramMap获取路线参数时出现错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44974088/

10-10 18:49