【问题标题】:Getting error of "error TS2339: Property 'user' does not exist on type 'Object'. "出现“错误 TS2339:“对象”类型上不存在属性“用户”的错误。”
【发布时间】:2020-10-18 14:32:59
【问题描述】:

错误 TS2339:“对象”类型上不存在属性“用户”。

export class LoginComponent implements OnInit {
  user = new BehaviorSubject<Userlogin>(null);
  constructor( private route: ActivatedRoute,
    private router: Router,private http:HttpClient) { }
  ngOnInit() {
  }
  loginClicked(form:NgForm)
  {
    const email = form.value.email;
    const password = form.value.password;
    const login = { email :email,password:password};

    //alert(password);
    this.http.post('http://localhost:3007/api/signin',login).subscribe(responseData => {
      console.log(responseData);
      if(responseData.user.name)
    {
        this.handleAuthentication(responseData.user.email,responseData.user._id,responseData.user.name);
        this.router.navigate(['/main']);
      }
    })
    form.reset();
  }

【问题讨论】:

    标签: html node.js angularjs mongodb-query


    【解决方案1】:

    只需使用any 绕过 TypeScript 类型检查:

    this.http.post('http://localhost:3007/api/signin',login).subscribe(responseData: any => {
    

    更好的做法是使用您为响应数据创建的自定义类型或接口。

    【讨论】:

      猜你喜欢
      • 2018-07-16
      • 1970-01-01
      • 2019-01-21
      • 2016-08-13
      • 2020-07-07
      • 2018-07-10
      • 1970-01-01
      • 2017-12-20
      • 2016-11-14
      相关资源
      最近更新 更多