Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n service not working with validatiors #37

Open
shobhit12345 opened this issue Aug 17, 2018 · 1 comment
Open

i18n service not working with validatiors #37

shobhit12345 opened this issue Aug 17, 2018 · 1 comment

Comments

@shobhit12345
Copy link

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) }
);
}

@JacobSiegle
Copy link
Contributor

JacobSiegle commented Nov 12, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants