Sujeet Raman

Sujeet Raman

  • 862
  • 927
  • 354k

how to bind api model state message(error msg) in typescript

May 31 2018 5:26 AM
Hi i have a save funtion in my angular app.if save is failed i need to show error message that returning from api.what i tried is..
in my service;
  1. private handleError(error: Response) {  
  2. return Observable.throw(error.text());  
  3. }  
  4. save(id: any) {  
  5. .map(res => <string[]>res.json())  
  6. .catch(this.handleError);  
  7. }  
component.ts:
  1. save() {  
  2. this.Service.save(this.id)  
  3. .subscribe(response => {  
  4. this.res= response;  
  5. },  
  6. (error) => {  
  7. this.errorMsg = error  
  8. alert(this.errorMsg)  
  9. });  
  10. }  
/final output am getting in alert : [{ "Message": null, "ModelState": [{ "Message": "enter valid range, the range is conflicting with range 8.00 and 17.00" }] }]
 
but i need to show only "enter valid range, the range is conflicting with range 8.00 and 17.00"
 
can anyone help me?

Answers (7)