Angular2 [ngClass] Conditional fails with Spaces

1k Views Asked by At

I have an ngClass conditional that functions fine on class names without spaces, but when i try to do something like below and i toggle isTrue on button click, the class changes from "btn btn-primary" to "btn-default". The space in there seems to be throwing it off. Am i missing something

[ngClass]="{ 'btn btn-default': isTrue, 'btn btn-primary': !isTrue}"
1

There are 1 best solutions below

0
On BEST ANSWER

Take the common one out, and have the rest of the expression in an ngClass directive

class="btn" [ngClass]="{ 'btn-default': isTrue, 'btn-primary': !isTrue}"