1

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

Johan Hirsch
  • 557
  • 4
  • 21
  • Check my answer with example https://stackoverflow.com/questions/58262752/in-reactive-forms-of-angular-why-the-parameter-passed-in-formcontrolname-is-pas/58263869#58263869 – Karthick Manoharan Oct 07 '19 at 09:14

1 Answers1

2

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.
Nicholas K
  • 15,148
  • 7
  • 31
  • 57
  • hi, but for better performance I recommend using ```@Attribute``` instead of a ```@Input``` https://netbasal.com/getting-to-know-the-attribute-decorator-in-angular-4f7c9fb61243 – mojtaba ramezani Oct 07 '19 at 09:05