如何根据angular 2中的某些条件更改md-card的背景颜色?

How to change the background colour of md-card based on some condition in angular 2?

我正在通过循环 *ngFor 动态显示卡片。我想根据 condition.For 例如更新卡片背景颜色如果满足某些条件,则卡片背景为绿色。否则,卡片背景颜色不变或更改为红色。如何在 Angular 2 中实现这种动态行为?我尝试使用 *ngIf,但随后布局变得一团糟。我只想根据条件更改背景颜色,而不影响任何布局更改。对于响应行为,我使用的是 flex 布局。

<div fxLayout="row" fxLayoutWrap style="padding-bottom: 25px; 
                                        padding-top: 25px;
                                        margin: auto;
                                        justify-content: center">  
    <md-card fxFlex.gt-md="45" 
             fxFlex.md="45" 
             fxFlex.sm="auto" 
             fxFlex.xs="100" 
             *ngFor="let data of myArray"
             [style.background]="'lightBlue'"
              style="margin:5px;">

        <md-card-content>
            <h1></h1>
            <h2></h2>
            <h2></h2>
        </md-card-content>
    </md-card> 
</div>

这也有效[style.background]="condition ? 'lightBlue':'yellow'"