Last active
December 11, 2018 20:57
-
-
Save luillyfe/fd8bbe6528c6d4d9034534f2337f2c17 to your computer and use it in GitHub Desktop.
Angular: event emmiter
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
/** *** */ | |
@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