Data binding is done to coordinate communication between a component and its template .
There are four types of data binding
Interpolation
This is the simplest and the best way of data binding
<h1>{{pagTitle}}</h1>
Property Binding ( One way data binding )
Square bracket [ ] is used to property binding. We take any html properties and bind it to our model
<img[src]="product.imargeurl"></span>
Event Binding
Parenthesis is ( ) is used to specify event binding. There are no event directives in angular 2
<button (click)="toggleImage()">Show</h1>
Two way data binding (Banana in a Box)
We use the square brackets because it's a property, but we also use the parenthesis. This syntax is called Banana in a Box ([()])
- [ ] Square bracket is used to indicate property binding
- ( ) is used for event binding to send a notification to the user entered data back to the class property
Note: ngModel directive a is part of FormsModule. We need to import it in AppModule
<input [(ngModel)]="listFilter"/>
Great blog, I was searching this for a while. Do post more like this.
ReplyDeleteAngularjs Training in Chennai
Angular 7 Training in Chennai
AWS course in Chennai
DevOps Certification Chennai
ReactJS Training in Chennai
Robotics Process Automation Training in Chennai
Data Science Course in Chennai
Data Science Training in Chennai