// 使用了observable返回
ngOnInit() {
this.hero$ = this.route.paramMap
.switchMap((params: ParamMap) =>
// getHero返回的是observal,而此控件会被angular复用
// 可能上一次getHero还没有完成,下一次请求又来了,所以要用switchMap将其打平,以提高效率
this.service.getHero(params.get('id')));
}
// 使用了快照,直接返回
ngOnInit() {
let id = this.route.snapshot.paramMap.get('id');
this.hero$ = this.service.getHero(id);
}