我有一个实现,其中parent希望通过使用子组件上可用的@Input
个参数将某些数据传递给子组件.然而,这种数据传输是可选的,家长可以根据需要传递数据,也可以不传递数据.组件中是否可以有可选的输入参数.我在下面描述了一个场景:
<parent>
<child [showName]="true"></child> //passing parameter
<child></child> //not willing to passing any parameter
</parent>
//child component definition
@Component {
selector:'app-child',
template:`<h1>Hi Children!</h1>
<span *ngIf="showName">Alex!</span>`
}
export class child {
@Input showName: boolean;
constructor() { }
}