首页 > 解决方案 > 离子服务错误:“响应”类型上不存在属性“用户”

问题描述

我找不到合适的解决方案,我有代码

登录.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)
      });
    });
  }

身份验证服务.ts

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

我在ionic serve上遇到了这个错误。为什么会这样?。

这是我的错误截屏

标签: ionic3angular6ionic-serve

解决方案


我通过给定的代码解决了我的问题

身份验证服务.ts

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

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

感谢@phonolog 提供参考


推荐阅读