簡體   English   中英

無法讀取undefine的屬性…,位於Object.callbackFromNative在angular 2中

[英]Cannot read property … of undefine , at Object.callbackFromNative In angular 2

我有一個流代碼

declare var Speech: any;
    export class Lesson implements OnInit {
       text = '';
       constructor()
{
this.text = 'hh';
}
ToSpeech(){
  Speech.listen(this.listenSucess);
}
listenSucess(result){
this.text = reuslt;
}

文件Speech.js

var Speech= (function () {
return {
   listen:funtion(sucess){
      window.plugins.speechRecognition.startListening(function (result) {
          success(result);
      }
   }
}

我有一個錯誤,如:

Cannot read property 'this.text' of undefined 
at Object.callbackFromNative

我將回調用於此功能,謝謝。

您是否嘗試過胖箭頭=>而不是function 因為thisfunction內部無法訪問

var Speech = (() => {
return {
   listen = (success) => {
      window.plugins.speechRecognition.startListening((result) => {
          success(result);
      }
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM