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 相同的语法,但我想它不支持这种方式..那么还有哪些其他类似的方式呢?:)
可以只使用三元运算符
[color]="coDeliverySlotView.slotId === bookedSlot.slotId ? 'black' : 'grey'"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3893 次 |
| 最近记录: |