i18n-polyfill icon indicating copy to clipboard operation
i18n-polyfill copied to clipboard

i18n service not working with validatiors

Open shobhit12345 opened this issue 6 years ago • 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) } ); }

shobhit12345 avatar Aug 17 '18 10:08 shobhit12345

Edit: Looking at it again, provide a constructor that provides the I18n polyfill in ConfirmMatchValidator and it should work.

JacobSiegle avatar Nov 12 '18 02:11 JacobSiegle