簡體   English   中英

如何在另一個組件中使用的組件內添加 ngClass 條件

[英]how to add ngClass condition inside a component which is used in another component

我是 angular 的新成員,我有一個網格,它有一個使用 Kendo 的詳細視圖,當我單擊該行時,另一個組件中的詳細信息將被綁定:

 <div *kendoGridDetailTemplate="let dataSource">
 <category-details [ngClass]="{'positive':dataSource.comment=='VPN'}"></app-category-details> 
</div>

當評論是 VPN 時,我的數據源的其中一項是評論我想使用 CSS 正面更改背景顏色:

 .positive {
    background-color: green;
}

上面的代碼不起作用,也沒有給我任何錯誤,如果在另一個組件中添加條件,通常添加這樣的條件應該可以工作??任何幫助都會得到重視

在全局 css 文件中定義您的.positive class。

你的ngClass會這樣:

[ngClass]="dataSource.comment=='VPN' ? 'positive':''"

很可能您只需要為category-details組件設置ViewEncapsulation.None

@Component({
...
  encapsulation: ViewEncapsulation.None
})
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM