我有这样的事情:
[ngClass]="{className: singleNumber == arrayOfNumbers}
如何比较1 === [1,2,3,4]
?如果我这样做,它可以工作:arrayOfNumbers [0]
答案 0 :(得分:1)
为什么不让自己更容易,并在ts中进行比较并检查模板上的bool?
<强> HTML 强>
[class.className]="isInArray"
<强> TS 强>
arrayOfNumbers = [1,2,3,4];
//in some part where you want to trigger the check
foo(myNumber: number) {
this.isInArray = this.arrayOfNumbers.indexOf(myNumber) !== -1
}
答案 1 :(得分:0)