【问题标题】:Property 'then' does not exist on type '() => Promise<{}>'. - Ionic 3类型 '() => Promise<{}>' 上不存在属性 'then'。 - 离子 3
【发布时间】:2020-04-11 17:40:54
【问题描述】:

方法

  hola() {
        return new Promise((resolve, reject) => {
          if(true) {
            resolve(true)
          }
        })
    }

调用方法

this.hola.then(data => console.log(data));

错误

类型 '() => Promise' 上不存在属性 'then'。

我已经尝试重新启动 ionic serve 但它一直抛出该错误

【问题讨论】:

  • 尝试调用函数:this.hola().then(...)(带括号)。
  • 操作!谢谢,这是问题

标签: angular ionic-framework ionic3


【解决方案1】:

调用方法 hola 时缺少括号。

this.hola().then(data => console.log(data));

【讨论】:

    【解决方案2】:

    当你调用方法时,试试这个,将它存储在“any”类型的变量中,使其忽略proprety的“存在”

        var a:any = this.slides.getActiveIndex()
        a.then(data => {
            console.log(data)
        })
    

    【讨论】:

      猜你喜欢
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      • 2016-12-31
      相关资源
      最近更新 更多