0
學習一些TypeScript。 試圖讓這個位代碼的工作:如何操作變量範圍?
...
ocrText: string;
...
foo() {
Tesseract.recognize(<Tesseract.ImageLike>document.getElementById('image'))
.then(function(result) {
console.log(result);
this.ocrText = result.text;
});
}
收到此錯誤:Uncaught TypeError: Cannot set property 'ocrText' of undefined
控制檯日誌確實顯示對象的屬性和值。
如何從「結果」對象中提取「文本」屬性的局部值到全局範圍?
重新標記爲這與TypeScript無關 –