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

@Output() - Child to Parent

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

@Output() နှင့် EventEmitter သည် child component မှ parent component သို့ events/data pass လုပ်ရန် အသုံးပြုသည်။

typescript
// child.component.ts
import { Component, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-child',
  template: `
    <button (click)="sendData()">Send to Parent</button>
  `
})
export class ChildComponent {
  @Output() dataEvent = new EventEmitter<string>();
  
  sendData() {
    this.dataEvent.emit('Hello from Child!');
  }
}

// parent.component.ts
@Component({
  selector: 'app-parent',
  template: `
    <app-child (dataEvent)="receiveData($event)"></app-child>
    <p>{{ message }}</p>
  `
})
export class ParentComponent {
  message = '';
  
  receiveData(data: string) {
    this.message = data;
  }
}
You should see
(Child component ၏ button ကိုနှိပ်လျှင် parent component တွင် 'Hello from Child!' ဟု ပေါ်လာမည်)
@Output() - Child to Parent | Thuta Learning