Each syntax has its own purpose.
1) Event Binding
This is a one-way binding to the internal on the external component. Called as event . The external component will call someMethod when the click event is fired from the internal component or from the current tag .
(click)="someMethod()"
Example: here button the click handler calls the onClickMe() function
@Component({ selector: 'click-me', template: ` <button (click)="onClickMe()">Click me!</button> {{clickMessage}}` }) export class ClickMeComponent { clickMessage = ''; onClickMe() { this.clickMessage = 'You are my hero!'; } }
2) One-way data binding
This is a one-way connection with the external to the internal . This will pass some.property to the src property in the internal component or tag .
[src]="some.property"
Example. Here we bind the value of the name property to the innerText property
<h1 [innerText]="name"></h1>
or
<h1>{{ name }}</h1>
3) Two-way data binding
And this is a two-way binding from internal to external and vice versa . This will do two things.
[(ngModel)]="some.property"
Example: here the input value will be updated when username updated. And also, when we enter another value in the input, the username will be updated. So, here you get two-way data bindings. And under the hood with [(ngModel)], it creates one-way and event bindings. These are the lines
<input [(ngModel)]="name"> <p>Hello {{ name }}!</p>
are equal
<input [value]="name" (input)="name = $event.target.value"> <p>Hello {{ name }}!</p>
For deep knowledge you can find in the documentation
source share