亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將不同的樣式應用于引導卡

將不同的樣式應用于引導卡

尚方寶劍之說 2022-09-23 17:05:09
我正在使用Angular 9,使用引導4卡應用NGFOR來繪制來自數據庫的盡可能多的元素。我有以下數組,該卡具有不同的樣式,我希望它們以隨機方式應用于每個數組。public color_border = ["border-left-warning", "border-left-info", "border-left-primary"]卡代碼如下:必須更改 div 卡左邊框信息。我已經嘗試了一個新的NGFOR,但它復制了一切。<!-- Pending Requests Card Example -->    <div class="col-xl-3 col-md-6 mb-4" *ngFor="let data of miDataInterior.DatagreenhouseRecuperado; let i = index">         <div class="card border-left-info shadow h-100 py-2">          <div class="card-body">            <div class="row no-gutters align-items-center">              <div class="col mr-2">                <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">{{data.medidas[0].sensor_type[0].name_comun}}</div>                <font SIZE=3> {{data.medidas[0].marca}} </font>                                    <font SIZE=3>({{data.medidas[0].recvTime | date:'dd-MM-yy h:mm:ss a'}})</font>                <div class="h5 mb-0 font-weight-bold text-gray-800">{{data.medidas[0].attrValue | number:'1.0-1'}} {{data.medidas[0].sensor_type[0].medida}}</div>              </div>              <div class="col-auto">                <i class="fas fa-chart-bar fa-2x text-gray-300"></i>              </div>            </div>          </div>        </div>      </div>如何應用該 div 中color_border變量中包含的內容?感謝您的幫助。
查看完整描述

2 回答

?
ABOUTYOU

TA貢獻1812條經驗 獲得超5個贊

備用邊框


[ngClass]="color_border[i%3]"

一個隨機的你需要做一個函數(你不能在.html內使用數學)


[ngClass]="getRandomColor()"


getRandomColor()

{

   return this.color_border[Math.floor(Math.random()*this.color_border.length]

}

如果你 miDataInterior.Datagreenhouse避難所有一個屬性“顏色”從 0 到 2 你可以使用


[ngClass]="color_border[data.color]"

注意 有幾種方法可以使用 [ngClass],請參閱文檔


查看完整回答
反對 回復 2022-09-23
?
精慕HU

TA貢獻1845條經驗 獲得超8個贊

試試這個。

<div *ngFor="let color_border of color_border" class="card shadow h-100 py-2 " [ngClass]="{{color_border}}">



查看完整回答
反對 回復 2022-09-23
  • 2 回答
  • 0 關注
  • 98 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號