68
rated 0 times
[
73]
[
5]
/ answers: 1 / hits: 35611
/ 9 Years ago, wed, august 5, 2015, 12:00:00
Following the guide from the Angular2 site I have this html:
<input #something (keyup)=doneTyping($event)>
<button (click)=add(something .value)>Add</button>
with this controller:
@Component({
selector: 'my-app',
appInjector: [SomeService]
})
@View({
templateUrl: 'index-angular',
directives:[NgFor]
})
class MyAppComponent {
name: string;
stuff: Array<string>;
constructor(someService: SomeService) {
this.name = 'Angular2Sample';
this.stuff= someService.getStuff();
}
add(st: string){
this.stuff.push(st);
}
doneTyping($event) {
if($event.which === 13) {
this.stuff.push($event.target.value);
$event.target.value = null;
}
}
}
When the user hits enter in the input, the doneTyping method clears the input with $event.target.value = null;
.
However I can't come with a way of doing the same after pushing the button.
More From » angular