2016-11-29 2 views
1
私.TSファイル内

コードは、私は私のhtmlファイルで使用する必要があるオブジェクトは、profileObjの構造は次のようにprofileObjです表示データ(.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());    
    } 

です

{ 
    "statusCode" : "200", 
    "message"  : "success", 
    "ngoDetails" : [ 
{"ngoId":"1","ngoName":"Test 1","emailId":"[email protected]"}]} 

しかし、私はエラーを取得しています{{profileObj.statusCode}}与えている:

zone.js:357 Error: Uncaught (in promise): Error: Error in ./Profile class Profile - inline template:28:9 caused by: Cannot read property 'statusCode' of undefined

私はRESOする助けてくださいこのエラーはありません。

+1

を検索します;' – JCDenton

答えて

2

"?"あなたのHTML内の表記profileObjが存在する場合は、コンソールでの出力あなたが `にconsole.log(this.profileObj)を実行いただきました、唯一のそれはからstatusCode

{{profileObj?.statusCode}} 
+0

amazing..thisは伝説的です –