Set input field placeholder from pipe

longbow picture longbow · Nov 15, 2016 · Viewed 7.9k times · Source

I would like to dynamically set <input type='text' placeholder=' {{ 'somestring' | getText }}'> placeholders using pipes. (this method does not work)

The pipe itself works perfectly fine e.g. <p>{{ myVariable | getText}}</p> will correctly render, as well as <p>{{ 'someString' | getText}}</p>

How does one use this to dynamically set placeholder strings?

Answer

Poul Kruijt picture Poul Kruijt · Nov 15, 2016

You can either use Matthias's suggestion or use double quotes for attribute/property/binding values. As a matter of fact, -always- use double quotes!

<input type="text" placeholder="{{ 'somestring' | getText }}">

or

<input type="text" [placeholder]="'somestring' | getText">