Components and Data Binding
Components and Data Binding
What is a Component
Two-way Binding: It is a derived binding that uses both property binding and the two-way
binding under the hood. This binding is used to display a value and also to update the value when
a new value is entered in the UI. ngModel is a built-in directive that supports two-way binding.
The following snippet shows how it is used:
<input type="text" [(ngModel)]="name" />
Event Binding: We can use event binding to capture a variety of user-initiated events to
initiate logic in our component class.
<button (click)="onSave()">Save</button>
Component Interaction
Input(): Inputs allow you to pass data down to a child component. It works by using
the Input() decorator to allow data to be passed via the template.
● Create a property in parent component
● Bind the property in css selector of the child component
● Declare a property in child component followed by @Input
Do not forget to import Input from @angular/core
Output(): allow you to emit data upwards to a parent component. It uses output()
decorator for the purpose.
Thank You