Skip to content

Instantly share code, notes, and snippets.

@luillyfe
Last active December 11, 2018 20:57
Show Gist options
  • Save luillyfe/fd8bbe6528c6d4d9034534f2337f2c17 to your computer and use it in GitHub Desktop.
Save luillyfe/fd8bbe6528c6d4d9034534f2337f2c17 to your computer and use it in GitHub Desktop.
Angular: event emmiter
/** *** */
@Component({
...
template: `
<div>
...
<button (click)="mutateProps()">Mutate!</button>
</div>
`,
})
export class NewsComponent {
...
@Output() changeTitle: EventEmitter<any> = new EventEmitter();
mutateProps() {
this.changeTitle.emit("Title changed!")
};
}
/** *** */
<news ... (changeTitle)="changeTitle($event)"></news>
<button (click)="printState()">Print parent state</button>
/** *** */
export class AppComponent {
...
changeTitle(event) {
this.title = event;
}
printState() {
console.log(`News title: ${this.title}, News content: ${this.content}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment