最佳答案
您可以在 html 中使用这样的条件
[style.background-color]="a.xx? 'purple': 'turquoise'"
或者在你的组件中,例如:
@Component({
selector: 'hello',
template: `
<a-item *ngFor="let a of catalogue"
[a]="a"
[style.background-color]="a.xx ? 'green': 'red'">
</a-item> ` })
您可以定义一个类,并在有人单击其他框时更改该类。也就是说,类“.previous_selected”和“now_selected”以及 onclick 新元素会更改新元素将具有的类 now_selected,而前一个元素将具有另一个类
其他选项:
示例:
import { Component } from '@angular/core'
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
colorA = 'red'
colorB = 'blue'
}
在 HTML 中
<div [style.color]="isSelected ? colorA : colorB">Some example text</div>
isSelected 可以是一个表示 true 或 false 的函数。
您可以找到更多信息here
关于css - Angular - 具有多重选择的事件和非事件 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65922231/