Angular @Input Decorator Explained
In Angular, the @Input decorator is used to pass data from a parent component to a child component. By using the @Input decorator on the input property of the child component, you can bind properties in the parent component template and pass data to the child component.
Input properties defined by the @Input decorator can receive data from the parent component and be used in the child component. The parent component can pass values to the input properties of the child component through property binding, allowing the child component to perform relevant operations or display using these values.
The syntax of the @Input decorator is as follows:
@Input() propertyName: propertyType;
“Where propertyName represents the name of the input property, and propertyType represents the type of input property.”
After using the @Input decorator, the parent component can pass values to the input properties of the child component in the template by binding attributes. For example, in the parent component, you can use it like this:
<app-child [propertyName]="value"></app-child>
In the child component, you can use the @Input decorator to receive values passed from the parent component and use them in the child component. For example, in the child component, you can use it like this:
@Input() propertyName: propertyType;
The purpose of the @Input decorator is to facilitate data transfer between parent and child components, allowing the parent component to pass data to the child component. This enables communication between components, enhancing their reusability and flexibility.