![](/img/trans.png)
[英]Display data collected from MYSQL to html page using AngularJs and PHP
[英]Display data from Angularjs2 file(.ts) in html page
我的.ts文件中的代碼是
constructor(
private config : ConfigService,
private http: Http){
this.getWS('ngoName')
.do((data) => {
console.log(data);
this.saveObj(data);
}).toPromise();
}
saveObj(data:any){
this.profileObj = data;
console.log(this.profileObj);
}
getWS(ngoName:string):any{
return this.http.get(this.config.serverBaseURL + "ngos.php?ngoId=1")
.map((res: Response) => res.json());
}
我必須在我的html文件中使用的對象是profileObj,profileObj的結構是這樣的
{
"statusCode" : "200",
"message" : "success",
"ngoDetails" : [
{"ngoId":"1","ngoName":"Test 1","emailId":"ritesh@gmail.com"}]}
但是當我給{{profileObj.statusCode}}時,我得到了錯誤:
zone.js:357錯誤:未捕獲(承諾中):錯誤:./ Profile類配置文件中的錯誤-內聯模板:28:9由以下原因引起:無法讀取未定義的屬性'statusCode'
請幫助我解決此錯誤。
采用 ”?” HTML中的表示法,如果profileObj僅存在,則它將搜索statusCode
{{profileObj?.statusCode}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.