离子3中“对象”类型中不存在如何修复属性?

时间:2018-03-16 08:45:16

标签: javascript angular ionic-framework ionic2 ionic3

我已将 API 称为获取数据,但我收到错误 对象中的对象上不存在属性 sellerDto 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");
        }
  });
}

1 个答案:

答案 0 :(得分:16)

尝试输入变量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");
        }
  });