Created
April 20, 2018 22:25
-
-
Save nerdic-coder/1059a912d6a5a296140314d971f424ac to your computer and use it in GitHub Desktop.
heroes.tsx two-way binding
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
import { Component, State } from '@stencil/core'; | |
import { Hero } from '../../models/hero'; | |
@Component({ | |
tag: 'app-heroes', | |
styleUrl: 'heroes.css' | |
}) | |
export class Heroes { | |
@State() private hero:Hero = { | |
id: 1, | |
name: 'Windstorm' | |
}; | |
handleChangeName(event) { | |
this.hero = { | |
id: this.hero.id, | |
name: event.target.value | |
}; | |
} | |
render() { | |
return ( | |
<div class='app-heroes'> | |
<h2>{ this.hero.name.toUpperCase() } Details</h2> | |
<div><span>id: </span>{this.hero.id}</div> | |
<div> | |
<label>name: | |
<input type="text" value={this.hero.name} onInput={(event) => this.handleChangeName(event)} placeholder="name" /> | |
</label> | |
</div> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment