我一直在尝试根据条件设置标签的data-color
属性值<li>
。这是我需要从中检查数据的示例数组:
{
Notifications: [
{
notification: "Example Notification",
notification_type: 1
},
{
notification: "Example Notification 2",
notification_type: 2
},
{
notification: "Example Notification 2",
notification_type: 3
]
}
这是我正在接收的数组,我需要<li>
根据通知类型设置标签的数据颜色。
这是我的<li>
标签:
<li class="feed-item" *ngFor= "let notification of Notificationslist" data-content="" data-color="green">
我需要设置data-color
为green,red and yellow
取决于通知类型,有人可以帮助我如何实现这一点。谢谢。
更新资料
我也想设置data-content,它也是一种字体真棒的unicode,它很好,但是当我尝试通过一个函数来获取它时,它只是显示一个字符串而不是图标。
采用
<li [attr.data-color]="notification.color">
如果要进行一些计算以获得颜色,请使用以下方法包装:
<li [attr.data-color]="getColorForNotification(notification)">
getColorForNotification(notification: Notification) {
switch (notification.notification_type){
case 1:
return 'green';
default:
return 'red'
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句