[英]Set different colors each row index in html table using Angular 4
I would like to set different colors for selected rows programatically each time when a button outside the table is clicked. 每次单击表格外部的按钮时,我想以编程方式为选定的行设置不同的颜色。 I am using the latest version of angular.
我正在使用最新版本的angular。
I know how to set row color with css but do not know how to influence the css class programatically in typescript. 我知道如何使用CSS设置行颜色,但不知道如何在打字稿中以编程方式影响CSS类。
.ui-table .ui-table-tbody > tr:nth-child(1) {
background-color: #2DA449;
}
Is there some way to edit the css class to set the child index and b-color in typescript? 有什么方法可以编辑CSS类以在打字稿中设置子索引和b-color?
Typescript 打字稿
export class MyComponent{
items:any[];
changeColors(){
// I'm just selecting the first row for this example but you have to define your own logic
this.items[0].color ="#ddd";
}
}
HTML 的HTML
<button (click)="changeColors()">Change colors<button/>
<table>
<tr *ngFor="let item in items;let i=index" [style.color]="item.color">
...
</tr>
</table>
More documention can be found https://angular.io/guide/template-syntax#binding-targets 可以找到更多文档https://angular.io/guide/template-syntax#binding-targets
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.