[英]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.