1import { Component, Output, EventEmitter } from '@angular/core';
2
3@Component({
4 selector: 'app-child',
5 template: `
6 <button (click)="sendMessage()">Send Message</button>
7 `,
8 styleUrls: ['./child.component.css']
9})
10export class ChildComponent {
11
12 message: string = "Hola Mundo!"
13
14 @Output() messageEvent = new EventEmitter<string>();
15
16 constructor() { }
17
18 sendMessage() {
19 this.messageEvent.emit(this.message)
20 }
21}
22
1import { Component } from '@angular/core';
2
3@Component({
4 selector: 'app-parent',
5 template: `
6 Message: {{message}}
7 <app-child (messageEvent)="receiveMessage($event)"></app-child>
8 `,
9 styleUrls: ['./parent.component.css']
10})
11export class ParentComponent {
12
13 constructor() { }
14
15 message:string;
16
17 receiveMessage($event) {
18 this.message = $event
19 }
20}
21