[英]How can i use a global variable in a If on angular .ts like JavaScript inside a component
看這個問題。 如何在IF語句中使用在函數上設置的值。 我想我需要使用let將該函數設置為全局函數,但無法正常工作感謝您的時間。
這里的代碼在哪里彈出問題。
問題出在變量valueSiorNo中。
謝謝!
/** changeValue */
public changeValue(event) {
console.log(event.target.value);
var valueSiorNo = event.target.value;
}
/** setConfirmation */
public setConfirmation(event, current = this.confirmation) {
const wizard = JSON.parse(sessionStorage.getItem('wizard'));
if( (wizard[0]["CAPITAL_PESOS"] == event.target.value) && ( ( valueSiorNo != null ))) {
this.confirmation = false;
this.mal = true;
this.cap = true;
}
else{
this.mal = false;
this.confirmation = true;
this.cap = true;
}
}
所述valueSiorNo
是的一部分changeValue
並且因此的范圍限於此功能,並且不能使用內部setConfirmation
功能。
您需要使其成為班級成員:
class MyClass {
valueSiorNo: any
constructor() { }
changeValue(event) {
console.log(event.target.value);
this.valueSiorNo = event.target.value;
}
/** setConfirmation */
public setConfirmation(event, current = this.confirmation) {
// access this.valueSiorNo in here
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.