2017-07-12 5 views
0

Ich erstelle eine App für Mobilgeräte mit Ionic Framework. So wie Sie sehen können, habe ich Ladebalken erstellt, und ich möchte es entlassen, nachdem alles fertig ist. Aber ich möchte auch meine Booleans ändern. Aber Konsole sagt, sie sind undefiniert. Warum?Warum ist Variable undefiniert, auch wenn sie definiert ist?

export class AfterEditPage { 

    public loaded_image = base64Image; 
    public showMainContent: boolean = true; // I am interacting with this one 
    public showAdditionalContent: boolean = false; // and this one 
    public processing_Result: string = ""; 

    constructor(public loadingctrl: LoadingController, public alertctrl: AlertController, public navCtrl: NavController, public navParams: NavParams) { 

    } 

    recognizeImage() { 

    let resultText; 
    console.log(resultText); 
    let loader = this.loadingctrl.create({ 
      content: 'Processing...' 
    }); 

    console.log(this.processing_Result); 
    loader.present().then(() => { 
      Tesseract.recognize(this.loaded_image) 
      .progress(function (p) {}) 
      .then(function (result) { 
        resultText = result.text; console.log(resultText); 
        loader.dismiss().then(() => { 
          this.showMainContent = !this.showMainContent; // undefined 
        this.showAdditionalContent = !this.showAdditionalContent; // undefined 
        }); 
       }); 
       }); 
     } 
    } 
+1

Zwei Wörter ändern müssen: [Pfeil-Funktionen] (https://www.typescriptlang.org/docs/handbook/functions .html # this). –

+0

Arrow Funktionen hier 'then (Funktion (Ergebnis) {' – alexanderbird

+0

'This' ist das globale Objekt hier und nicht Ihre Instanz von' AfterEditPage'. – balteo

Antwort

0

Sie benötigen Pfeil-Funktionen verwenden, so dass Sie Ihren Code

loader.present().then(() => { 
      Tesseract.recognize(this.loaded_image) 
      .progress((p) => {}) 
      .then((result) => { 
        resultText = result.text; console.log(resultText); 
        loader.dismiss().then(() => { 
          this.showMainContent = !this.showMainContent; 
        this.showAdditionalContent = !this.showAdditionalContent; 
        }); 
       }); 
       }); 
     } 
    } 
Verwandte Themen