I have an implementation where parent wants to pass certain data to child component via the use of @Input
parameter available at the child component. However, this
Input values are optional by default. Your code will fail only when it tries to access properties of inputs that are not actually passed (since those inputs are undefined
).
You can implement OnChanges or make the input a setter instead of a property to get your code executed when a value is actually passed.
export class child {
@Input set showName(value: boolean) {
this._showName = value;
doSomethingWhenShowNameIsPassed(value);
}
constructor() { }
}