Primeng: ExpressionChangedAfterItHasBeenCheckedError when preselect a p-radioButton

Created on 12 Jul 2019  路  2Comments  路  Source: primefaces/primeng

I'm submitting a ...

[x] bug report 
[ ] feature request
[ ] support request

Stackblitz demo

Minimal Angular 8/PrimeNg 8 app that demonstrates the issue

https://stackblitz.com/edit/angular-zhmbkf

Current behavior

Initially getting ExpressionChangedAfterItHasBeenCheckedError (exactly like in #3100) after upgrading to Angular 8 and PrimeNG 8. In Angular 7/PrimeNg 7 the error did not occur.

_My 2 cents:_

Looks like setting static to true in

@ViewChild('rb', { static: false }) inputViewChild: ElementRef;

(https://github.com/primefaces/primeng/blob/master/src/app/components/radiobutton/radiobutton.ts#L57)

resolves the issue.

Expected behavior

Well, no error would be nice :-)

Minimal reproduction of the problem with instructions
Just open the Stackblitz and you will see the error in the console

Please tell us about your environment:

  • Angular version: 8.1.1

  • PrimeNG version: 8.0.1

  • Browser: Chromium 75.0.3770.90

  • Language: TypeScript 3.4

defect

Most helpful comment

@MustafaElKhalifa yes, but this is a hack that triggers change detection for the whole application. Also not suitable for me as I would need to apply this to 20+ components. :`-(

All 2 comments

I was able to pass this issue by using setTimeOut
I set the default value in ngOnInit

ngOnInit() {
    setTimeout(()=>{
      this.formGroup.get('input_form_control_name').setValue('0');
    },0)
}

@MustafaElKhalifa yes, but this is a hack that triggers change detection for the whole application. Also not suitable for me as I would need to apply this to 20+ components. :`-(

Was this page helpful?
0 / 5 - 0 ratings