DEV Community

Faisal Ahmed
Faisal Ahmed

Posted on

OutPut Decorator Simple Example

App.component

<h1 style="color: blue;">I am parent= {{title}}</h1>

<h2 style="color: red;">Data is coming from Child to Parent=  {{comingFromChildData}}</h2>

<app-child (updateDataEvent)="sendFunc($event)"></app-child>
Enter fullscreen mode Exit fullscreen mode
  title: any = "Hello Parent";
  comingFromChildData: any;

  sendFunc(item: any){
    console.log("I am from child data = ", item);
    this.comingFromChildData = item;
  }
Enter fullscreen mode Exit fullscreen mode

Child.component

<h2>I am child!</h2>
<button (click)="updateDataEvent.emit(myChildData)">Update Data</button>
Enter fullscreen mode Exit fullscreen mode
import { Component, Output, EventEmitter } from '@angular/core';
Enter fullscreen mode Exit fullscreen mode
   @Output() updateDataEvent = new EventEmitter<any>();

  myChildData: any = "ami dusto";
Enter fullscreen mode Exit fullscreen mode

Top comments (0)