【发布时间】:2018-06-13 04:45:40
【问题描述】:
这两者有什么区别:
<li [ngClass]="{disabledField: condition1 && condition2 && condition3}">Click</li>
对
<li [ngClass]="{disabledField: shouldDisableField()}">Click</li>
在组件类中:
shouldDisableField(): boolean{
return this.condition1 && this.condition2 && this.condition3;
}
【问题讨论】:
-
优雅和简洁的方式是使用getter而不是函数
get shouldDisableField: boolean { return this.condition1 && this.condition2 && this.condition3 }<li [class.disabledField]="shouldDisableField">Click</li> -
my answer有什么不清楚的地方吗?
-
@AngularInDepth.com 不,非常明确的答案。
标签: javascript angular angular5