For me, using only the following solution did not help:
<input [ngModel]="phone | PhoneNum" (ngModelChange)="phone = $event">
Problem: assigning the phone = $ event did not work for all cases until the user had to focus the input element.
Therefore, I suggest using the ALSO ElementRef Object to handle the inline input element:
HTML:
<input type="text" name="points" #points maxlength="8" [(ngModel)]="range" (ngModelChange)="range=saverange($event, points)">
component:
onChangeAchievement(eventStr: string, eRef): string { //Do something (some manipulations) on input and than return it to be saved: //In case you need to force of modifing the Element-Reference value on-focus of input: var eventStrToReplace = eventStr.replace(/[^0-9,eE\.\+]+/g, ""); if (eventStr != eventStrToReplace) { eRef.value = eventStrToReplace; } return this.getNumberOnChange(eventStr); }
The idea is here:
Providing the "(ngModelChange)" method for setting the Setter:
(ngModelChange) = "range = saverange ($ event, points)"
Enabling direct access to the main Dom element with this call:
eRef.value = eventStrToReplace;
source share