Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <span style="color:red">{{usererror.username}} </span>
  2. ...other items here
  3. <span style="color:red">{{usererror.password}} </span>
  4.  
  5. export class LoginComponent implements OnInit{
  6. public usererror={
  7. username:"",
  8. password:""
  9. }
  10.  
  11. //this function is called after a post request
  12. onLoginError(error:any){
  13.  
  14. let message= JSON.parse( error._body);
  15. console.log(error._body); //first log
  16. console.log(message) //second log
  17.  
  18.  
  19. }
  20.  
  21. }
  22.  
  23. [{"field":"username","message":"Username cannot be blank."},
  24. {"field":"password","message":"Password cannot be blank."}]
  25.  
  26. onLoginError(error:any){
  27.  
  28. let message= JSON.parse( error._body);
  29. let message= JSON.parse( error._body);
  30.  
  31. for (var i=0; i<message.length; i++){
  32. this.usererror.message[i].field = message[i].message; //this fails since the
  33. //usererror doesnt have (message[i].field) property
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement