1
我遇到的挑战与SO中的面孔相同here我在component.ts的订阅方法中未定义,即使在我的服务中我有数据。 请参见下面的代码 p.component.tsAngular 2可观察订阅显示undefined
private getPayItems():void{
console.log('In getPayItems');
this._payItemService.getPayItems()
.subscribe(data => {
this.payItemArray = data;
console.log(data);
},
(error:any) =>{
this.alerts.push({ msg: error, type: 'danger', closable: true });
})
}
p.service.ts
getPayItems():Observable<Payitem[]>{
let actionUrl = this.url + "/GetPayItem";
return this._http.get(actionUrl, { headers: this.headers })
.map((response: Response) => {
<Payitem[]>response.json() ;
console.log(<Payitem[]>response.json()); //This logs the Object
})
.catch(this.handleError);
}
你刚才救了我的一天,先生!谢谢 –