Data binding
The simplest form of binding is string interpolation, which uses double curly braces {{ expression }}
. This template expression is evaluated and then converted to string by Angular. It can take expressions such as {{ 'Hell' + 'o' }}
which outputs Hello
, or {{ 100 === 100 }}
which returns a Boolean of true. It can even contain functions such as {{ 1 + getAge() }}
.
Here's another case where we use a template expression that references a template input variable {{ feed }}
:
<li *ngFor="let feed of feeds" (click)="show(feed)">{{ feed }}</li>
When the user interacts with a view, it's often required to intercept these events and perform some activity. The events such as click
can be intercepted by surrounding the event name in parentheses and assigning it to a handler of the event, such as show(...)
. You can have other types of binding, such as property binding, which is used for binding to the property of an element or component. The syntax is of the form [property]="......