这是表中一行的代码
<tr class="user-item" *ngFor="let device of group.devices" (click)="$event.stopPropagation()" ngClass="device.onlineState == 'Offline' ? 'highlight' : 'highlight2'">
<td class="qkFix">{{ device.deviceId }}</td>
<td class="qkFix">{{ device.alias }}</td>
<td class="qkFix" *ngIf="device.onlineState == 'Online'" ngClass="colorOnline">{{ device.onlineState }}
<span class="dotOnline"></span>
</td>
<td class="qkFix" *ngIf="device.onlineState == 'Offline'" ngClass="colorOffline">{{ device.onlineState }}
<span class="dotOffline"></span>
</td>
<td class="qkFix">
<button type="button" class="btn btn-default btn-xs" (click)="$event.stopPropagation(); showDevice(device); editDeviceDialog()">
<i class="material-icons">{{ (auth.hasPermissions(['update-devices'], true)) ? 'edit' : 'open_in_new'}}</i>
</button>
<button [disabled]="!(auth.hasPermissions(['delete-devices'], true))" type="button" class="btn btn-default btn-xs" (click)="$event.stopPropagation();deleteDevice(device)">
<i *ngIf="(auth.hasPermissions(['delete-devices'], true))" class="material-icons" (click)="$event.stopPropagation();deleteDevice(device)">delete</i>
<i *ngIf="!(auth.hasPermissions(['delete-devices'], true))" class="material-icons" (click)="$event.stopPropagation()">delete</i>
</button>
<button *ngIf="device.onlineState == 'Online'" [disabled]="!(auth.hasPermissions(['remote-control'], true))" type="button" class="btn btn-default btn-xs" (click)="$event.stopPropagation(); remoteSession(device)">
<i *ngIf="(auth.hasPermissions(['remote-control'], true))" (click)="$event.stopPropagation();remoteSession(device)" class="material-icons">swap_horiz</i>
<i *ngIf="!(auth.hasPermissions(['remote-control'], true))" (click)="$event.stopPropagation()" class="material-icons">swap_horiz</i>
</button>
</td>
</tr>专用ngClass码
ngClass="device.onlineState == 'Offline' ? 'highlight' : 'highlight2'",我希望行具有类 highlight ,如果该设备的onlineState是脱机的。 device.onlineState either returns Online or Offline。如果onlineState是联机的,就不应该有一个类.
发布于 2018-03-28 10:13:48
尝试将ngClass放在括号中,即[ngClass]。想了解更多细节。
答案:
[ngClass]="device.onlineState == 'Offline' ? 'highlight' : 'highlight2'"如果要添加multiple classes,可以这样做:
option1:
[ngClass]="condition ? 'class1 class2 class3' : 'class4 class5 class6'"Option2:
[ngClass]="{'class1': condition1, 'class2': Condition2}"发布于 2018-03-28 10:15:44
你可以这样做:
[class.highlight]="device.onlineState == 'Offline'"您已经必须执行[ngClass]而不是ngClass来允许表达式的执行。
发布于 2018-03-28 10:17:40
ngClass是一个指令,它以类的名称作为属性值和条件作为值,接受对象作为参数,例如:
[ngClass]="{'highlight': device.onlineState === 'Offline'}"您可以添加这样的多个类:
[ngClass]="{'highlight other-class': device.onlineState === 'Offline'}"或
[ngClass]="{'highlight': device.onlineState === 'Offline', 'other-class': condition}"https://stackoverflow.com/questions/49531743
复制相似问题