类型“() => Promise<{}>”上不存在属性“then”。- 离子 3

poi*_*sm2 3 ionic-framework ionic3 angular

方法

  hola() {
        return new Promise((resolve, reject) => {
          if(true) {
            resolve(true)
          }
        })
    }
Run Code Online (Sandbox Code Playgroud)

调用方法

this.hola.then(data => console.log(data));
Run Code Online (Sandbox Code Playgroud)

错误

类型“() => Promise<{}>”上不存在属性“then”。

我已经尝试重新启动离子服务,但它不断抛出该错误

aru*_*mar 9

调用方法hola 时缺少括号。

this.hola().then(data => console.log(data));
Run Code Online (Sandbox Code Playgroud)


小智 2

当您调用该方法时,请尝试这样做,将其存储在“any”类型的变量中,使其忽略属性的“存在”

    var a:any = this.slides.getActiveIndex()
    a.then(data => {
        console.log(data)
    })
Run Code Online (Sandbox Code Playgroud)