呼喚遠方
2023-04-20 17:15:13
我有一個調(diào)用ngDoCheck(). 該 func 調(diào)用了幾個重新分配我的變量的 func。但是變量變化只在函數(shù)中發(fā)生,而不是全局變量。myVariable總是0。myVariable = 0;ngDoCheck(): any { const word: string = this.form.get('word').value; this.PasswordStrengthMeter(word, this.myVariable); console.log('Value: ' + this.myVariable); }Mainfunc(word: string, myVariable: number): any { this.SecondaryFunc(word, myVariable); this.AnotherSecondaryFunc(word, myVariable); }
2 回答

郎朗坤
TA貢獻1921條經(jīng)驗 獲得超9個贊
的值被myVariable傳遞給Mainfunc,而不是引用。
如果您想更改全局變量,請this.myVariable直接使用您的其他SecondaryFunc和AnotherSecondaryFunc.
myVariable = 0;
...
Mainfunc(word: string): any {
this.SecondaryFunc(word);
this.AnotherSecondaryFunc(word);
}
SecondaryFunc(word: string): any {
this.myVariable = 5;
}
AnotherSecondaryFunc(word: string): any {
this.myVariable = 6;
}
添加回答
舉報
0/150
提交
取消