![]() |
VOOZH | about |
In Angular 2, we can pass the value of a variable between two components (from parent to child) using the Input Decorator. Using these Input decorators we can also set the default values of the properties. Below I had detailly elaborated in a comprehensive way on how to set default values for Angular 2 component.
Syntax:
@Input() PropertyName = Default Value /* @Input country = 'India' */
Approach:
import { Input } from '@angular/core';
Implementation by code: app.component.html:
app.component.ts:
child.component.ts:
child.component.html:
Conclusion:
As we are passing country property as 'India', it will be displayed. But when it comes to capital as we are not passing any value it displays the default value in child.component.ts file.
Output:
👁 Image