Angular တွင် Hooks များစွာ
Hooks များစွာကို တစ်ပြိုင်နက် သတ်မှတ်နိုင်ပါသည်။ ကျွန်ုပ်တို့ လေ့လာပြီးသော hooks နှစ်ခုဖြင့် ဥပမာပြသကာ ၎င်းကို မည်သို့လုပ်ဆောင်သည်ကို ကြည့်ရအောင်။
Interface နှစ်ခုကို import လုပ်ပါမည်။
import { OnInit, OnDestroy } from '@angular/core';
၎င်းတို့ကို class သို့ ချိတ်ဆက်ပါမည်။
export class UserComponent implements OnInit, OnDestroy {
}
ကျွန်ုပ်တို့၏ hooks နှစ်ခုကို ရေးသားပါမည်။
export class UserComponent implements OnInit, OnDestroy {
constructor() {
console.log('constructor is started');
}
ngOnInit() {
console.log('onInit is applied');
}
ngOnDestroy() {
console.log('onDestroy is applied');
}
}
Hooks နှစ်ခုလုံး၏ အလုပ်လုပ်ပုံကို if reactive condition
ပေါ်တွင် စစ်ဆေးပါ။
Hooks နှစ်ခုလုံး၏ အလုပ်လုပ်ပုံကို reactive loop ပေါ်တွင် စစ်ဆေးပါ။