Binding a plain string value to a component's @Input
property in Angular
can be done in either of the two ways:
<my-component inputProperty="my-property-value"></my-component>
or:
<my-component [inputProperty]="'my-property-value'"></my-component>
Is one of them generally preferred over the other? (Are there exceptions?)
Is there a general convention regarding this?
Is this addressed in any Angular style guide (couldn't find anything in the official style guide).
From the One-time string initialization in the Angular docs:
You should omit the brackets when all of the following are true:
- The target property accepts a string value.
- The string is a fixed value that you can put directly into the template.
- This initial value never changes.