How can I get the values after a model has changed? The (change)
event does fire before the model change. I do not want to use event.target.value
<input type="checkbox" (change)="mychange(event)" [(ngModel)]="mymodel">
public mychange(event)
{
console.log(mymodel); // mymodel has the value before the change
}
This question is related to
angular
This worked for me
<input
(input)="$event.target.value = toSnakeCase($event.target.value)"
[(ngModel)]="table.name" />
In Typescript
toSnakeCase(value: string) {
if (value) {
return value.toLowerCase().replace(/[\W_]+/g, "");
}
}
If this helps you,
<input type="checkbox" (ngModelChange)="mychange($event)" [ngModel]="mymodel">
mychange(val)
{
console.log(val); // updated value
}
Use the (ngModelChange)
event to detect changes on the model
Source: Stackoverflow.com