我有这个表=>点击
<table class="table table-bordered" *ngFor="let list of lists">
<caption>{{ list.nodename }}</caption>
<thead>
<tr>
<th>Название сервиса</th>
<th>Статус</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let service_rec of list.servicelist">
<td>{{ service_rec.name }}</td>
<td>{{ service_rec.status }}</td>
</tr>
</tbody>
</table>
我的任务是设置颜色- green = online
, red = offline
,但我不知道怎么做!请帮帮我。
我得到数据在这个json
ngOnInit(){
this._service.getServices()
.subscribe(lists => this.lists = lists)
}
和
getServices(){
return this._http.get(this._url)
.map(res => res.json());
}
你的问题不是很清楚,但我猜你想要这样的东西。
<tr *ngFor="let service_rec of list.servicelist" >
<td>{{ service_rec.name }}</td>
<td [style.background-color]="service_rec.status == 'Online' ? 'green' : 'red'">{{ service_rec.status }}</td>
</tr>