ngClass将数字与动态数组进行比较 - Angular [duplicate]

ngClass compare number with array of numbers dynamically - Angular [duplicate]

This question already has an answer here:

I have something like this:

[ngClass]="{className: singleNumber == arrayOfNumbers}

How do I compare 1 === [1,2,3,4] ? it works if I do this: arrayOfNumbers[0]

Why not make it easier for yourself and have the comparison in the ts and check the bool on template?




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