【问题标题】:Icon Color for different Status Angular 6不同状态Angular 6的图标颜色
【发布时间】:2019-07-11 11:08:09
【问题描述】:

我对角度有这样的看法:

这是我的dashboard.component.ts

export class DashboardComponent implements OnInit {
  tablePresetColumns;
  tablePresetData;
 ngOnInit() {
  this.tablePresetColumns = [{id: 1,content: 'Username'},{id: 2,content: 'Status'}];
  this.tablePresetData = [[{id: 1,content: 'john.doe@random.com'},{id: 2,content: 'Busy'}],[{id: 1,content: 'test2@random.com'},{id: 2,content: 'overload'}]];
 }
} 

这就是我在dashboard.component 上调用表格的方式:

<div eds-tile class="xl-4" style="height: 700px">
<eds-tile-title>User on Shift</eds-tile-title>  
<eds-table [columns]="tablePresetColumns" [data]="tablePresetData" [modes]="['compact', 'dashed']"></eds-table>
</div>

我的编辑表:

selector: 'eds-table',
template: "<table class=\"table\" [ngClass]=\"modes\">\n  <thead *ngIf=\"columns\">\n    <tr>\n      <th *ngFor=\"let col of columns\">\n        {{col.content}}\n      </th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr *ngFor=\"let row of data\">\n      <td *ngFor=\"let cell of row\">\n        {{cell.content}}\n      </td>\n    </tr>\n  </tbody>\n</table>\n",

我的问题是,我应该怎么做才能让我的视图至少变成这样,我的意思是状态忙碌时有条件,

图标颜色为绿色,或空闲为黄色,过载为红色(在文本右侧):

需要支持,谢谢...

【问题讨论】:

    标签: html css angular angular6 less


    【解决方案1】:

    你可以在&lt;td&gt;使用下面的

    <td *ngFor="let cell of row" 
      [ngStyle]="{'color': (cell.content === 'Busy') ? 'green' : (cell.content === 'overload') ? 'red' : (cell.content === 'idle') ? 'yellow' : ''}">{{cell.content}}
    </td>
    

    通过以下方式,

    <td [ngClass]="{
                    'busy' : cell.content == 'Busy',
                    'idle' : cell.content == 'Idle'
                    'overload' : cell.content == 'Overload'
                 }" *ngFor="let cell of row"> {{cell.content}} </td>
    

    在你的 CSS 中

    .busy {
        color: green;
    }
    
    .idle {
        color: yellow;
    }
    
    .overload {
        color: red;
    }
    

    更新答案

       <td *ngFor="let cell of row"> {{cell.content}} 
          <span class ="dot" [ngClass]="{
            'dot-red' : cell.content == 'Busy',
            'dot-green' : cell.content == 'Idle',
            'dot-yellow' : cell.content == 'overload'}"></span></td>
    
    .dot {
      height: 20px;
      width: 20px;
      border-radius: 50%;
      display: inline-block;
    }
    .dot-red {
      background-color: red;
    }
    .dot-green {
      background-color: green;
    }
    .dot-yellow {
      background-color: yellow;
    }
    

    【讨论】:

    • 嗨@dileepkumar jami,我认为它只是将我的文本颜色变为红色、绿色或黄色。不是我想要的文本右侧的图标
    • 我可以知道哪个图标吗?
    • 你想在文本旁边放一些图标吗?
    • yupp @dileepkumar jami,作为我的问题和上面的示例图片
    • 我想要小圆形图标,就像我在@dileepkumar jami 上面的图片一样
    猜你喜欢
    • 2019-07-01
    • 2014-11-06
    • 1970-01-01
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多