【发布时间】:2017-09-20 14:23:40
【问题描述】:
您好,我正在尝试使用带枚举的条件类。我之前在ngSwitchCase 中使用过html 中的枚举,并且遇到了与我现在遇到的相同的错误。当我添加一个名为该枚举的属性并将其分配给该枚举时,它将起作用。
工作示例:
<ng-container *ngFor="let column of columns" [ngSwitch]="column.dataType">
<td *ngSwitchCase="DataType.Text">{{getPropertyValue(row,column.propertyName)}}</td>
<td *ngSwitchCase="DataType.Date">date</td>
<td *ngSwitchCase="DataType.Number">number</td>
<td *ngSwitchDefault>default</td>
</ng-container>
ts
private DataType = DataType;
不工作:
<span *ngClass="(column.sortType === SortType.Ascending)? 'privilege-grid-sortasc': (column.sortType === SortType.Descending)?'privilege-grid-sortdesc':'privilege-grid-sortnone'"></span>
我也试过[ngClass] ="{'class-name': var === enum,...}"
ts
private SortType = SortType;
错误信息:
无法读取未定义的属性“升序”
【问题讨论】: