【问题标题】:Tesseract callback with Angular - 'this' is undefined带有 Angular 的 Tesseract 回调 - 'this' 未定义
【发布时间】:2017-06-20 10:20:43
【问题描述】:

我正在尝试使用 Angular 2 开始 Tesseract。

Tesseract.recognize(file)
    .progress(function (p) { console.log('progress', p) })
    .then(function (result) {
      this.resultText = result.text;
    })
}

问题出在行上:this.resultText = result.text;。 我收到错误'无法读取未定义的属性'resultText'

我不确定为什么这是未定义的

【问题讨论】:

  • 那行得通。谢谢!

标签: angular tesseract.js


【解决方案1】:

使用箭头函数语法在回调中正确绑定this

Tesseract.recognize(file)
    .progress((p) => { console.log('progress', p) })
    .then((result) => {
      this.resultText = result.text;
    })
}

【讨论】:

    【解决方案2】:

    了解更多信息 检查这个video

    你反驳的问题是这个引用的词汇。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-18
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 2015-04-29
      • 2012-05-21
      相关资源
      最近更新 更多