Search code examples
angularangular2-styleguide

Is there a convention for using Angular brackets binding notation for @Input properties?


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).


Solution

  • From the One-time string initialization in the Angular docs:

    You should omit the brackets when all of the following are true:

    1. The target property accepts a string value.
    2. The string is a fixed value that you can put directly into the template.
    3. This initial value never changes.