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
You can use the ( ? ) operator as below
import {Component,Input} from '@angular/core';
@Component({
selector:'child',
template:`Hi Children!
Alex!`
})
export class ChildComponent {
@Input() showName?: boolean;
constructor() { }
}
The parent component that uses the child component will be as
@Component({
selector: 'my-app',
template: `
Hello {{name}}
`,
})
export class App {
name:string;
constructor() {
this.name = 'Angular2'
}
}
LIVE DEMO