繁体   English   中英

如何在组件中的JavaScript等有角.ts的If中使用全局变量

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM