我有一个简单的列表,其中包含来自循环的几行。当我单击或悬停在任何行上时,它会变为活动状态,再次单击其他行时,当前行将处于活动状态,而上一个行将处于非活动状态。直到现在工作正常。但是在该行中有一些图标我需要显示或隐藏与活动相同。当我悬停/单击时,这些图标将显示并再次隐藏鼠标或单击下一行。这是代码以下
app.component.html
<ul>
<li *ngFor="let row of groups;let i = index" [ngClass]="{'active': clickedIndex == i}" (click)="clickedIndex == i? clickedIndex = null : clickedIndex = i"><span>{{row.items}}</span>---><span>Icon1</span><span>Icon2</span></li>
</ul>
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
clickedIndex: number = 0
groups = [{ "id": 1, "name": "pencils", "items": "red pencil", "Status": [{ "id": 1, "name": "green" }, { "id": 2, "name": "red" }, { "id": 3, "name": "yellow" }], "loc": [{ "id": 1, "name": "loc 1" }, { "id": 2, "name": "loc 2" }, { "id": 3, "name": "loc 3" }] }, { "id": 2, "name": "rubbers", "items": "big rubber", "Status": [{ "name": "green" }, { "name": "red" }], "loc": [{ "name": "loc 2" }, { "name": "loc 3" }] }, { "id": 3, "name": "rubbers1", "items": "big rubber1", "Status": [{ "name": "green" }, { "name": "red" }], "loc": [{ "name": "loc 2" }, { "name": "loc 3" }] }]
}
app.component.css
.active{
background:red;
color:#FFf;
}