Articles in this section
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.
  1. In src/app.component.html file.
    [workDays]="getWorkDays()"
    
  1. In src/app.component.ts file.
    public getWorkDays() {
      let workDays = [1,2,3];
      return workDays;
    }
    

 

To prevent the schedule re-rendering


  1. 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';
    

 

  1. 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
Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied