1

code in my .ts file is

  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());            
  }

the object which i have to use in my html file is the profileObj, structure of profileObj is like this

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

but when i am giving {{profileObj.statusCode}} i am getting error:

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

please help me to resolve this error.

1
  • 1
    Whats the output in console when you run console.log(this.profileObj); Commented Nov 29, 2016 at 6:43

1 Answer 1

2

use "?" notation in your HTML , if profileObj exists only then it will search for statusCode

{{profileObj?.statusCode}} 
Sign up to request clarification or add additional context in comments.

1 Comment

amazing..this is legendary

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.