1

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?

qwe asd
  • 1,598
  • 3
  • 21
  • 31

1 Answers1

5

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" />
qwe asd
  • 1,598
  • 3
  • 21
  • 31
ranakrunal9
  • 13,320
  • 3
  • 42
  • 43