I have an Angular 7 app that contains a text input. The value of the text input is bound to a component level variable accountNumber.
<input type="text" [(ngModel)]="accountNumber" (change)="isAccountNumberFlagged(accountNumber)" />
I have a component method isAccountNumberFlagged(number: string) that checks to see if the accountNumber is flagged and if it is display a warning (by making a specific element visible. I have this method bound to the change event and it works as expected.
What doesn't work as expected is when I change the value in the text input after having entered a value that has been "flagged" and tab to another control. The (change) event does not fire in these cases.
Sequence of events
- Component loads
- Change the value in the text input =
(change)event fires - Enter a flagged account number =
(change)event fires and flagged warning displays - Change the value in the text input =
(change)DOES NOT fire (even if I enter another or the same flagged account number)
Clearly I am missing something about how the (change) event works. What am I doing wrong?