ngClass with method returning true,false and null

175 Views Asked by At
    HTML

enter code here <div>[ngClass] = "{'red-color' : colorChanged() === true, 
            'green-color': colorChanged() === false,
            'black-color': colorChanged() === null }" >{{value}}
    </div>

    
    
    TS

    public colorChanged(){
        this.data.forEach((el)=>{
          if(el.colorChange && el.colorChange == true){
            if(el.value >= 0){
              this.isColorChanges = true;
            }
            else{
              this.isColorChanges = false
            }
          }
          else {
            this.isColorChanges =null ;
          }
          
        })
        return this.isColorChanges
      }
   

How do I write ngClass with method which is returning true, false and null. based on return value I need to change the color.

Here data is array of object which contain colorChange as key which is i'm passing value from parent component

0

There are 0 best solutions below