如何从角度路由器链接中的参数中获取值?
这是我的代码
组件.ts:
Hotels: struct_hotel;
id : struct_hotel['id']
constructor(
private activatedRoute: ActivatedRoute,
private _service: ResultService)
{
this.activatedRoute.queryParams.subscribe(params => {
let id= params['id'];
//console.log(id);
});
}
getDetails(id): void {
this._service.getHotel(this.id).then(Hotels => this.Hotels = Hotels);
}
ngOnInit():void {
this.getDetails(this.id);
}
服务 :
private apidetail = 'http://localhost/bobobox/public/api/v1/room/show';
getHotel(id: string ): Promise<struct_hotel>
{
const url = `${this.apidetail}/${id}`;
return this.http.get(url)
.toPromise()
.then(response => response.json() as struct_hotel[])
.catch(this.handleError);
}
我像这样在html上调用它{{Hotels.hotel_name}}
,我得到了错误ERROR TypeError: Cannot read property 'hotel_name' of undefined
谁能帮我 ?