i18n service not working with validatiors
shobhit12345 opened this issue · 1 comments
Hi
I have some hard coded messages in validator file ,i have injected the i18n from component class, but its not working , i m not able to extract the value in .xlf file.
import { AbstractControl, ValidationErrors } from '@angular/forms';
import {I18n} from "@ngx-translate/i18n-polyfill";
export class ConfirmMatchValidator {
static match(confirm: string, actual: string, i18n:I18n) {
i18n("hi , For testing");
return (formGroup: AbstractControl): ValidationErrors | null => {
//some validator code
return null;
};
}
}
in component class
private updatingEmailForm() {
this.updateEmailForm = this.fb.group(
{
newEmail: ['', [Validators.required, Validators.maxLength(50), EmailValidator]],
confirmEmail: ['', [Validators.required, Validators.maxLength(50), EmailValidator]]
},
{ validator: ConfirmMatchValidator.match('confirmEmail', 'newEmail',this.i18n) }
);
}
Edit: Looking at it again, provide a constructor that provides the I18n polyfill in ConfirmMatchValidator and it should work.