【问题标题】:how to fix property does not exist on type 'Object' in ionic 3?如何修复离子3中“对象”类型不存在的属性?
【发布时间】:2018-08-25 06:21:24
【问题描述】:

我已调用 API 来获取数据,但我收到错误 sellerDto 中的类型 Object 上不存在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");
        }
  });
}

【问题讨论】:

    标签: javascript angular ionic-framework ionic2 ionic3


    【解决方案1】:

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

    【讨论】:

    • 感谢它为我工作,但请告诉我先生我们为什么通过 (data:any)?
    • 因为您的错误来自打字稿抱怨对象数据的类型。对象没有名为 sellDto 的属性。相反,我们告诉 typescript 数据实际上是 type any。在答案中对您有帮助请接受它以帮助他人
    猜你喜欢
    • 1970-01-01
    • 2020-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多