Home > front end >  Angular ng2-flatpickr Expression has changed after it was checked. Previous value for ng-pristine
Angular ng2-flatpickr Expression has changed after it was checked. Previous value for ng-pristine

Time:10-16

I'm new to angular, I want to use ng2-flatpickr library for pick the date as well as to show the user DOB, It works fine and I can get the date from api result and display in html date picker, but in console I'm getting this error

Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value for 'ng-pristine': 'true'. Current value: 'false'.

if I didn't use setDate and went to use this

this.generalForm.dob.setValue(response.general.dob);

the value will be set but wont appear on 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>

CodePudding user response:

use ChangeDetectorRef to tell that you updated the content after ngAfterContentChecked

 ngAfterContentChecked() {
  this.cdref.detectChanges();
  }
  • Related