angular - 尝试使用 paramMap 获取路由参数时出错

标签 angular

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/

相关文章:

javascript - 带事件发射器的触发功能

javascript - 如何正确地在存储中保存状态并检索它

angular - 如何在 Angular 列表中保留滚动位置?

angular - 可观察到的 : Cancel previous http request on new subscription call

jquery - 如何获得表行与 Angular 7 中最后两个值的差异?

javascript - 如何在 native 浏览器请求上设置 header ,或者在使用 Video.js 从 Microsoft Azure 播放视频时提供授权 header ?

多次触发 Angular @HostListener 事件

angular - 如何将登录表单发布到遗留服务器(没有 Ajax)?

css - Angular Material : How to change the background color for the mat spinner path

angular - 无法解析 ApplicationModule : (? 的参数)