I have a simple app which adds the textbox value to listbox when enter key is pressed in textbox. Here is my html code
<input type="text" value="{{ myText }}" (keypress)="keyEvent($event)" />
<select multiple="multiple" >
<option *ngFor="let item of itemsList">
{{item}}
</option>
</select>
here is my typescript component code
export class AppComponent {
title = `hello world app !`;
myText ='';
itemsList = [];constructor() {
}
ngOnInit() {
}
keyEvent(event)
{
if(event.keyCode === 13)
{
event.preventDefault(); // Otherwise the form will be submitted
this.itemsList.push(this.myText);
}
}
myText value is not getting updated . the value is always null.
Please help to figure out what is that i am missing while binding myText.