I Have a template-driven form with two-way data binding and validator
<input [(ngModel)]="myObj.name" someValidator>
How can I prevent sendind data from input do model if there are some validation errors? In my model I want to have only correct data from form.
You can attach a keyup function to the input and do whatever you wish to achieve.
<input [ngModel]="myObj.name" (keyup)="onChangeCheck($event.target.value)">
export class ParentCmp {
onChangeCheck(val){
console.log(val);
if( condition){
this.myobj.name = value;
}else{
// do nothing
}
}
}