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

51 Views Asked by At

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

1

There are 1 best solutions below

1
On BEST ANSWER

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.