Error on ionic serve : Property 'user' does not exist on type 'Response'

110 Views Asked by At

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

1

There are 1 best solutions below

0
On BEST ANSWER

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