亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在angular9中重新分配變量?

如何在angular9中重新分配變量?

呼喚遠方 2023-04-20 17:15:13
我有一個調用ngDoCheck(). 該 func 調用了幾個重新分配我的變量的 func。但是變量變化只在函數中發生,而不是全局變量。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 回答

?
精慕HU

TA貢獻1845條經驗 獲得超8個贊

如果它在同一個組件中,為什么要將該變量傳遞給每個函數?只需在該函數中使用它,因為它是一個全局變量。



查看完整回答
反對 回復 2023-04-20
?
郎朗坤

TA貢獻1921條經驗 獲得超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;

}


查看完整回答
反對 回復 2023-04-20
  • 2 回答
  • 0 關注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號