share event between multiple components angular io code example
Example 1: angular send data to parent component
import { Component, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'app-child',
template: `
<button (click)="sendMessage()">Send Message</button>
`,
styleUrls: ['./child.component.css']
})
export class ChildComponent {
message: string = "Hola Mundo!"
@Output() messageEvent = new EventEmitter<string>();
constructor() { }
sendMessage() {
this.messageEvent.emit(this.message)
}
}
Example 2: input property angular
<app-slider [title]="'This is a title'"> </app-slider>
.
.
@input() title: string;
constructor(){
}
<div id='slider' class='slider-big'>
<h1> {{title}}</h1>
</div>