Category / Section
How to overcome the infinite loop on method of property binding
1 min read
Issue replication step:
The ‘workDays’ property is given by property binding using the method as shown in the code below.The Scheduler will flicker and be re-rendered multiple times.
- In src/app.component.html file.
[workDays]="getWorkDays()"
- In src/app.component.ts file.
public getWorkDays() { let workDays = [1,2,3]; return workDays; }
To prevent the schedule re-rendering
- Need to import the ‘ChangeDetectionStrategy’ package from the ‘@angular/core’ in the app.component.ts file as follows, like below.
import { Component, ChangeDetectionStrategy } from '@angular/core';
- Use ‘ChangeDetectionStrategy.OnPush’ as shown in the following code snippet.
@Component({
selector: ‘app-root’,
providers: [WeekService, MonthService, ResizeService, DragAndDropService],
changeDetection: ChangeDetectionStrategy.OnPush
})
Please refer to the example from the following GitHub link.
Example – Scheduler with workDays property