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

Lifecycle Hooks

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

Lifecycle Hooks များသည် component ၏ creation နှင့် destruction အဆင့်များတွင် code များ run နိုင်ရန် Angular မှ ပေးထားသော methods များဖြစ်သည်။

typescript
import { Component, OnInit, OnDestroy, OnChanges } from '@angular/core';

export class MyComponent implements OnInit, OnDestroy, OnChanges {
  
  // Component instance created လုပ်ပြီး properties initialized ဖြစ်သောအခါ
  constructor() {
    console.log('Constructor called');
  }
  
  // Component initialized ဖြစ်ပြီး @Input properties set ပြီးသောအခါ
  ngOnInit() {
    console.log('Component initialized');
    // API calls များ ဒီမှာလုပ်သင့်သည်
  }
  
  // @Input properties ပြောင်းလဲသောအခါတိုင်း
  ngOnChanges(changes: SimpleChanges) {
    console.log('Input changed:', changes);
  }
  
  // View initialized ဖြစ်ပြီးသောအခါ
  ngAfterViewInit() {
    console.log('View ready');
  }
  
  // Component destroy လုပ်မည့်အချိန်
  ngOnDestroy() {
    console.log('Component destroyed');
    // Cleanup: unsubscribe, clear timers
  }
}
You should see
(Component lifecycle အဆင့်တိုင်းတွင် console messages များ ပေါ်လာမည်)
Lifecycle Hooks | Thuta Learning