BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Hi Team,
I have a Splitter layout and a sample TreeGrid inside a split panel. When the page is loaded, below console error appears.
I have reproduced the said scenario in below sample.
https://stackblitz.com/edit/angular-wmmmdc-wxaufg?devToolsHeight=33&file=src/app.component.ts
Seeking support to solve this issue.
@Component({
Aruna.
Hi Aruna,
We have checked the code you provided and found that invoking setTimeout with a delay of zero can resolve this issue. Please refer to the below code and sample for your reference.
@Component({ selector: 'my-splitter', template: `<ejs-splitter height="100%"> <e-panes> <e-pane size="200px"> <ng-template #content> ……….. </ng-template> </e-pane> <e-pane> <ng-template #content> <ng-template #container> </ng-template> </ng-template> </e-pane> </e-panes> </ejs-splitter> </div>`, }) …… ngAfterViewInit() { setTimeout(() => { const componentFactory = this.componentFactoryResolver.resolveComponentFactory( MyTreeGridComponent );
// add the component to the view const componentRef = this.container.createComponent(componentFactory);
}, 0); } |
regards,
Mallesh
Hi Mallesh,
Thank you for the solution provided.
I'd like to know in depth why we encountering ExpressionChangedAfterItHasBeenChecked error when I use multiple nested Syncfusion components defined in html template.
Is there any asynchronous mechanism in Syncfusion component rendering which cause this change detection issue?
Is there any cleaner way to solve change detection issue without using componentFactory ?
Aruna.
The reason you are encountering the ExpressionChangedAfterItHasBeenChecked error when using multiple nested Syncfusion components is due to the way Angular's change detection mechanism works. Angular's change detection mechanism ensures that all the bindings in the component tree are up to date and synchronized. This is achieved through a series of checks and updates that take place in a specific order.
When the change detection mechanism detects a change, it performs a full round of change detection to ensure that all the bindings are up to date. However, if a change is detected during the change detection process, it will trigger another round of change detection. This can lead to an infinite loop of change detection and cause performance issues.
In your case, the Syncfusion component rendering is asynchronous, which means that it can cause changes to occur after the initial change detection cycle has completed. This can result in the ExpressionChangedAfterItHasBeenChecked error being thrown.
Using the componentFactoryResolver and setTimeout method is a way to solve this change detection issue. By deferring the creation of the component until after the change detection cycle has completed, we can ensure that the bindings are up to date and prevent the error from being thrown.
Another approach to solving this issue is to use the ChangeDetectorRef.detectChanges() method to trigger a manual change detection cycle after the component has been initialized. This will force Angular to re-evaluate the bindings and update the view if necessary.
We hope this helps to clarify why you are encountering the ExpressionChangedAfterItHasBeenChecked error and provides some alternative solutions to the issue. If you have any further questions, please feel free to ask.