简体   繁体   中英

angular - how to combine few ngclass together in one div

I would like to combine multiple ngClass if else statement together, I have tried but not able to resolve it.

<div
    [ngClass]="[tabItem === 'unavailable' ? 'background-grey' : selected ? 'card-selected cursor' : 'cursor']"
    [ngClass]="[hasAlerts ? 'banner' : 'no-banner']">
</div>

My attempt:

<div
    [ngClass]="[{'banner': hasAlerts, 'no-banner': !hasAlerts}, tabItem === 'unavailable' ? 'background-grey' : selected ? 'card-selected cursor' : 'cursor']">
</div>

I'm finally able to resolve the issue by using this method

<div
[ngClass]="{'banner': !!alerts?.length, 'no-banner' : !alerts?.length, 'background-grey': tabItem === 'unavailable', 'cursor': tabItem === 'available', 'card-selected': selected}"
></div>   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM