0

I coudn't find a proper solution for this, I have the code

login.ts

login() {
    if(!this.login_form.valid)
      return;

    this.AuthService.login(this.login_form.value).subscribe((result) => {
      if((result.status).toString() == "Success" && result.user){
        localStorage.setItem('userData', JSON.stringify(result.user));
        this.nav.setRoot(HomePage);
      }
    }, (err) => {
          console.log(err)
      });
    });
  }

AuthService.ts

  public login(credentials) {
      return this.http.post(this.apiUrl + '/appLogin', JSON.stringify(credentials))
                .map((response: Response) => response);
  }

i'm getting this error on ionic serve . Why this happening?.

This is my error screen shot

AmiLinn
  • 344
  • 1
  • 11
  • 1
    [Type-checking](https://angular.io/guide/http#type-checking-the-response) your response might help. You can specify what type of Observable your expecting like: `this.http.post(...)` assuming your expecting the post method to return a User object. – Phonolog Jul 21 '18 at 09:00
  • @Phonolog, thanks for the link, my problem solved. – AmiLinn Jul 21 '18 at 10:24

1 Answers1

0

I solved my problem, by the given code

AuthService.ts

export interface User {
  status: string;
  user: {};
}

  public login(credentials) {
      return this.http.post(this.apiUrl + '/appLogin', JSON.stringify(credentials))
                .map((response: User) => response);
  }

Thanks to @phonolog for the reference

AmiLinn
  • 344
  • 1
  • 11