Skip to content

Instantly share code, notes, and snippets.

@nerdic-coder
Created May 12, 2018 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdic-coder/d8cd584b2b9d6f8abfdcaef0cef77fc2 to your computer and use it in GitHub Desktop.
Save nerdic-coder/d8cd584b2b9d6f8abfdcaef0cef77fc2 to your computer and use it in GitHub Desktop.
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