Skip to content

Instantly share code, notes, and snippets.

@nerdic-coder
Created May 12, 2018 10:52
Embed
What would you like to do?
addHero.ts
handleChangeName(event) {
this.hero = {
id: this.hero.id,
name: event.target.value
};
}
add(): void {
this.hero.name = this.hero.name.trim();
if (!this.hero.name) { return; }
this.heroService.addHero(this.hero).subscribe(hero => {
this.heroes.push(hero);
this.hero = {
id: this.hero.id,
name: ""
};
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment