我是 Angular 新手,我想使用 ng2-flatpickr 庫來選擇日期以及顯示用戶 DOB,它作業正常,我可以從 api 結果中獲取日期并顯示在 html 日期選擇器中,但在控制臺中我收到此錯誤
錯誤:NG0100:ExpressionChangedAfterItHasBeenCheckedError:運算式在檢查后已更改。'ng-pristine' 的先前值:'true'。當前值:“假”。
如果我沒有使用 setDate 并去使用它
this.generalForm.dob.setValue(response.general.dob);
該值將被設定但不會出現在 HTML 上!!
public dobDate:string
private _setGeneralValues(){
this._accountSettingsService.onSettingsChanged.pipe(takeUntil(this._unsubscribeAll)).subscribe(response => {
this.data = response;
this.dobDate = response.general.dob;
});
}
<ng2-flatpickr
[config]="birthDateOptions"
name="dob"
formControlName="dob"
[setDate]="dobDate"
required
></ng2-flatpickr>
uj5u.com熱心網友回復:
使用 ChangeDetectorRef 告訴您在 ngAfterContentChecked 之后更新了內容
ngAfterContentChecked() {
this.cdref.detectChanges();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/515368.html
標籤:有角度的
