Last active
November 18, 2017 09:11
-
-
Save raffaele-abramini/07c91f13bb9ee7615d709a3e66702514 to your computer and use it in GitHub Desktop.
Angular 4 - Event emitter - 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import EventEmitter and Output | |
import {Component, EventEmitter, Output} from '@angular/core'; | |
@Component({ | |
selector: 'app-my-component', | |
templateUrl: './my-component.component.html', | |
}) | |
export class MyComponent { | |
// Define the new output as an EventEmitter. | |
// We are also defining some data to be pass to the event listeners (someData) | |
@Output() myEvent = new EventEmitter<{someData: string}>(); | |
constructor() { | |
this.makeSomethingHappen(); | |
} | |
makeSomethingHappen() { | |
// Now that you have defined the event, you can invoke it whenever you want | |
// invoking the emit method. | |
this.myEvent.emit({ someData: 'Something happend' }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment