Thuta Learning
ရှာဖွေရန်
AdvancedWeb Developmentintermediate

Change Detection

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Change Detection သည် Angular မှ component data changes များကို detect လုပ်ပြီး view ကို update လုပ်သည့် mechanism ဖြစ်သည်။

typescript
import { ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';

// Default Change Detection (checks all the time)
@Component({
  selector: 'app-default',
  template: `<p>{{ data }}</p>`
})
export class DefaultComponent {
  data = 'Hello';
}

// OnPush Change Detection (checks only when @Input changes)
@Component({
  selector: 'app-optimized',
  template: `<p>{{ data }}</p>`,
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class OptimizedComponent {
  @Input() data: any;
  
  constructor(private cdr: ChangeDetectorRef) {}
  
  // Manually trigger change detection if needed
  updateData() {
    this.data = 'New value';
    this.cdr.markForCheck();  // Tell Angular to check
  }
}
You should see
(OnPush strategy သုံးခြင်းဖြင့် performance ကောင်းလာပြီး unnecessary checks လျှော့ချနိုင်သည်)
Change Detection | Thuta Learning