communication between components in angular code example

Example 1: angular send data to parent component

import { Component, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-child',
  template: `
      
  `,
  styleUrls: ['./child.component.css']
})
export class ChildComponent {

  message: string = "Hola Mundo!"

  @Output() messageEvent = new EventEmitter();

  constructor() { }

  sendMessage() {
    this.messageEvent.emit(this.message)
  }
}

Example 2: communication between components in angular

3 ways to communicate data between Angular components
Parent to Child: Sharing Data via Input
Child to Parent: Sharing Data via ViewChild with AfterViewInit
Child to Parent: Sharing Data via Output() and EventEmitter

Tags:

Misc Example