Skip to content

Instantly share code, notes, and snippets.

@raffaele-abramini
Last active November 18, 2017 09:11
Show Gist options
  • Save raffaele-abramini/07c91f13bb9ee7615d709a3e66702514 to your computer and use it in GitHub Desktop.
Save raffaele-abramini/07c91f13bb9ee7615d709a3e66702514 to your computer and use it in GitHub Desktop.
Angular 4 - Event emitter - 1
// 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