0
votes

I need a div to have a css-class when a variable cfgSelected is has a certain value .. here '1' (<- string!!)

<div [ngClass]="(cfgSelected ==='1')?'isActive':'isNormal'" 
     (click)="selectThisOne('1')">
bla ...
</div>

in the ts-file:

selectThisOne(id: any) {
    this.cfgSelected = id;
}

it works in --dev but when I want to build --prod it I get

ERROR in src\app\configurator\configurator.component.html(80,50): : Operator '===' cannot be applied to types 'number' and 'string'.

can someone please tell me what is wrong with that?

1
Make use of an integer instead, or at least parse it as such.Obsidian Age
To add, the === operator doesn't cast the arguments to the same type, but if you used == it could work (but not best practice)itsmewiththeface

1 Answers

0
votes

Change (cfgSelected ==='1') to (cfgSelected === 1)

Reason

Because prod does type checking 🌹