我創建了一個 FormGroup,根據是否選中復選框,部分需要禁用。這適用于我的代碼,但過了一段時間我發現它不適用于 Microsoft Edge(僅使用 Chrome 進行了測試)。它只會有反應我看了一下我的代碼,似乎我犯了一個錯誤,并且 Microsoft Edge 上顯示的 UI 是正確的,但 Chrome 中的 UI 卻不是。在我看來,這像是一個異步問題,因為如果我設置了console.log()after this.checkinForm.controls['releaseDropdown'].enable(),那么在第一次單擊該復選框后,它不會在 Chrome 中記錄任何內容。第二次重新單擊它后,它會啟用,但隨后該復選框未被選中,應該被禁用。有人看到我做錯了什么嗎?Stackblitz https://stackblitz.com/edit/angular-wqsd3y我的代碼如下所示:打字稿checkinForm: FormGroup;...ngOnInit(): void {... this.checkinForm = this.formBuilder.group({ isCheckedRelease: new FormControl(false), releaseDropdown: new FormControl({value: null, disabled: true}), newRelease: new FormControl({value: null, disabled: true}), description: new FormControl(null), isCheckedConfig: new FormControl(false) });...} onCheckboxReleaseClick(){ if(this.checkinForm.controls['isCheckedRelease'].value === true){ this.checkinForm.controls['releaseDropdown'].enable() this.checkinForm.controls['newRelease'].enable() }else{ this.checkinForm.controls['releaseDropdown'].disable() this.checkinForm.controls['newRelease'].disable() } }超文本標記語言<form [formGroup]="checkinForm"> <div> <label>The default chosen release in the configuration is: </label> <label style="color: red;"> {{defaultBranch}}</label> </div> <div> <label>Create or select a release for {{name}} </label> <input class="my-checkbox" formControlName="isCheckedRelease" type="checkbox" (click)="onCheckboxReleaseClick()" /> </div>
1 回答

溫溫醬
TA貢獻1752條經驗 獲得超4個贊
發現以下修復:
從 (click)
<div> <label>Create or select a release for {{name}} </label> <input class="my-checkbox" formControlName="isCheckedRelease" type="checkbox" (click)="onCheckboxReleaseClick()" /> </div>
到 (change)
<div> <label>Create or select a release for {{name}} </label> <input class="my-checkbox" formControlName="isCheckedRelease" type="checkbox" (change)="onCheckboxReleaseClick()" /> </div>
- 1 回答
- 0 關注
- 117 瀏覽
添加回答
舉報
0/150
提交
取消