簡體   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