Guest User

Untitled

a guest
May 18th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. export class LoginRequest {
  2. username : string;
  3. password : string;
  4. }
  5.  
  6. export class LoginResponse {
  7. token : string;
  8. message : string;
  9. status : string;
  10. }
  11.  
  12. export class LoginComponent {
  13. ...
  14. loginRes : LoginResponse;
  15. ...
  16.  
  17. login(loginReq : LoginRequest) {
  18. // here how can I get return object
  19. this.loginRes = this.loginService.login(this.loginReq);
  20. }
  21. }
  22.  
  23. export class LoginService {
  24. ...
  25. loginRes : LoginResponse;
  26. ...
  27.  
  28. login() {
  29. // here how can I return loginRes object
  30. this.http.post(API_URL + "weblogin", loginReq)
  31. .subscribe(
  32. res => {
  33. this.loginRes = res.json() as LoginResponse;
  34. },
  35. err => {
  36. this.loginRes = new LoginResponse();
  37. this.loginRes.message = "Failed to conntect the server";
  38. this.loginRes.status = "NOT_OK";
  39. this.loginRes;
  40. }
  41. );
  42. }
  43. }
Add Comment
Please, Sign In to add comment