import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<input [(ngModel)]="name" type="text" (input)="inputChange()">
<h3>{{name}}</h3> `
})
export class AppComponent {
name = 'Apple';
inputChange() {
this.name="Zebra";
}
}
here's my angular component. I have an input box and on every key input the function "inputChange()" is called which changes my name to "Zebra",
I have to validate the user input and return certain values for which I have to call the input event everytime they write something. I want the textbox value to be same as "Zebra" as my function changes the value no matter what the user types in the textbox. What am i doing wrong here?
Change your input event to keyup
<input [(ngModel)]="name" type="text" (keyup)="inputChange()">