How to pass a string value to a component in angular2

Andras Hatvani picture Andras Hatvani · Mar 25, 2016 · Viewed 48.3k times · Source

I'd like to pass a string value to a component in angular2, but it doesn't work with the default binding. I'm thinking of something similar to this:

<component [inputField]="string"></component>

Unfortunately, only expressions are allowed on the right side of the assignment. Is there a way to do this?

Answer

G&#252;nter Z&#246;chbauer picture Günter Zöchbauer · Mar 25, 2016

String literals can be passed in different ways:

<component inputField="string"></component>
<component [inputField]="'string'"></component>
<component inputField="{{'string'}}"></component>