0
我正在使用Ionic框架爲移動設備創建應用程序。正如你所看到的,我創建了加載欄,並且我想在完成所有工作後將其解除。但我也想改變我的布爾人。但控制檯說他們沒有定義。爲什麼?即使定義變量,爲什麼變量未定義?
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
});
});
});
}
}
兩個詞來使用箭頭功能:箭頭功能(https://www.typescriptlang.org/docs/handbook/functions的.html#這一點)。 –
這裏是箭頭函數'then(function(result){' – alexanderbird
'this'是這裏的全局對象,而不是'AfterEditPage'的實例 – balteo