【发布时间】:2017-06-19 03:16:48
【问题描述】:
我正在 Angular 2 中创建一个演示应用程序,并希望在我的组件中控制台 params['id'],id 来自查询参数。
为了实现这一点,我在我的组件中这样做:
ngOnInit(): void {
this.route.params
.switchMap(
(params: Params) =>
this.heroService.getHero(+params['id']);
console.log("ID :",params['id'])
).subscribe(hero => this.hero = hero);
};
但我得到了这个错误:
core.umd.js:3491 EXCEPTION: Uncaught (in promise): Error: Error in :0:0 caused by: params is not defined
ReferenceError: params is not defined
请建议我必须做什么来控制参数的 id ?
【问题讨论】:
标签: angular typescript