Ponpon32
Ponpon32

Reputation: 2200

what is the difference between those binding methods in angular?

In the angular tutorial there is this example:

<h3>
    <a [title]="product.name + ' details'">
      {{ product.name }}
    </a>
  </h3>

it works great if I am writing it like this:

<h3>
    <a title="{{product.name + ' details'}}">
      {{ product.name }}
    </a>
  </h3>

what is the difference? and what is the best practice?

Upvotes: 2

Views: 139

Answers (1)

Tony
Tony

Reputation: 20132

The first one is property binding using the anotation []

The second one is normal interpolation.

Difference between Interpolation and Property Binding.

Interpolation is a special syntax that Angular converts into property binding. It’s a convenient alternative to property binding.

Property Binding: to set an element property to a non-string data value, you must use property binding.

So to display none any type of data (include string) value use Property Binding or if you want to display normal string value use {{}} interpolation

Source: https://www.codementor.io/adekunleoyaniyi/interpolation-vs-property-binding-in-angular2-eu1tzbyn4

Upvotes: 6

Related Questions