Angular Material(组件)中的条件按钮颜色属性

Mac*_*ito 5 conditional-statements angular-material angular-components angular

我有一个需要输入的组件.. @Input() coDeliveryCandidates: DeliverySlotView[];

这在模板中使用:

<ng-container *ngFor="let coDeliverySlotView of (coDeliveryCandidates | async)">
  <button
    mat-raised-button
    [color]=""
  >
    {{ label  }}
  </button>
</ng-container>
Run Code Online (Sandbox Code Playgroud)

color 属性需要一个字符串作为值,我想做一些类似的事情:

[color]="{
  black: coDeliverySlotView.slotId === bookedSlot.slotId,
  grey: !coDeliverySlotView.slotId === bookedSlot.slotId
}"
Run Code Online (Sandbox Code Playgroud)

在这里,我使用与 ngClass 相同的语法,但我想它不支持这种方式..那么还有哪些其他类似的方式呢?:)

abn*_*317 6

可以只使用三元运算符

[color]="coDeliverySlotView.slotId === bookedSlot.slotId ? 'black' : 'grey'"
Run Code Online (Sandbox Code Playgroud)