I would like to use ng2-translate for placeholder. Only way to do this I found is use ng2-translate service and pass variable to placeholder like this:
class Form {
placeholder: string;
constructor(translate: TranslateService) {
translate.get('placeholder.value').subscribe(
(placeholder: string) => this.placeholder = placeholder,
);
}
}
<input type="email" placeholder={{placeholder}}/>
But it looks bulky. Is there way to use ng2-translate for placeholder with pipe or directive?
As per documentation, If your language json file is a below
{
"placeholder": {
"value" : "Your placeholder text"
}
}
then you can use translate
pipe
as below :
<input type="email" [placeholder]="'placeholder.value' | translate" />