【发布时间】:2019-07-19 11:19:20
【问题描述】:
处理可选输入参数的更好方法是什么?
@Input() public isActive?: boolean;
或
@Input() public isActive: boolean = undefined;
还有一个小困惑,下面的代码会产生什么结果以及为什么(如果在视图中未指定isActive)?
@Input() public isActive?: boolean = undefined;
与
<app-sth [otherParameter]="true"></app-sth>
【问题讨论】:
-
我猜
isActive将保持undefined并充当虚假值
标签: javascript angular