I am new to angular and i want to implement a custom validator who can trim the input field of model driven approach form.i am getting some problem in implementation.when i set the value using setValue() in the validator function infinite callstack will occure. So Please suggest me how i can update the form value and one more thing i want to use validators in the way i'm using.
Validator Function
static trimSpace(c:AbstractControl) {
console.log(c);
let v= c.value.replace(/\s\s+/g, ' ');
let valid=true;
console.log(v.trim());
c.setValue(v);
return true ? null : {
trimmed: true
}
}
Component Form
this.addressForm=this.fb.group({
firstName:['',Validators.compose([Validators.required,TrimValidator.trimSpace])]});