javascript - 如何修复 ionic 3 中类型 'Object' 上不存在的属性?

标签 javascript angular ionic-framework ionic2 ionic3

我已调用 API 获取数据,但出现错误 Property sellerDto does not exist on type Object in ionic3 并且我会尝试将数据声明为已声明的对象,但同样的错误会再次发生如何解决此错误?

/*
  @Copyright Notice:
  @(#)
  @Type: TS	
  @For:  create-accont.html.
  @Description : userLoggedInSuccess for create the user account 1st in the GCP 
 */
 public userData       : any = {};
userLoggedInSuccess(userObject) {
    //Enable the loader after call the FB function
    var self = this;
    //Declare the local variable
    self.url                  = "";
    self.API_HOST             = "";
    self.paramData                 = "";
    let userTypeKeyId = userObject.uid;

    let url = self.API_HOST + "/api/login/dto";
    let paramData  = "userTypeKeyId=" + userTypeKeyId;

    let headers =  {
      headers: new  HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded'})
    };

    //Pass the data into the API for check email is exist in the API or not
    self.http.post(url, paramData, headers).subscribe(data => {
      this.userData = data;
      if(this.userData.isLoggedIn) {
          //Here we will set the user Detail into the local-storage
          if(this.userData.userType == "seller" && this.userData.sellerDto == undefined){
            self.localStorage.set("defaultLanguage",    data.sellerDto.userTypeDto.defaultLanguage);
          }
        } else {
          console.log("user is no valid");
        }
  });
}

最佳答案

尝试输入变量 data :any

 self.http.post(url, paramData, headers).subscribe((data:any) => {
      this.userData = data;
      if(this.userData.isLoggedIn) {
          //Here we will set the user Detail into the local-storage
          if(this.userData.userType == "seller" && this.userData.sellerDto == undefined){
            self.localStorage.set("defaultLanguage",    data.sellerDto.userTypeDto.defaultLanguage);
          }
        } else {
          console.log("user is no valid");
        }
  });

关于javascript - 如何修复 ionic 3 中类型 'Object' 上不存在的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49316407/

相关文章:

javascript - 使用同位素javascript插件,我怎样才能摆脱差距?

javascript - 动态创建的js脚本onClick函数变量未绑定(bind)在当前值

javascript - 如果调整了一张卡片的大小,请连续调整所有卡片的大小

javascript - 从提供者函数获取值到另一个页面

javascript - 在异步回发上注册 javascript

javascript - 在上传带有水印的图像之前为图像添加水印

css - 如何改变 ionic 的导航栏大小?

javascript - 如何在 Ionic/Cordova 应用程序中保护我的 Google Maps Javascript V3 API key ?

angular - 从 Angular4 上的 md-dialog 获取数据

angular - 有什么方法可以更改 Angular Material 上的浏览器自动完成视觉效果吗?