简体   繁体   中英

ngClass mysteriously not working with Angular 6?

I have a very straightforward ngClass situation that's failing to work, and I'm completely flummoxed as to why:

<a [ngClass]="{'sortList' : activeSort }">Some link</a>

On the component, activeSort = false, and I can toggle true/false with a button. I've console.log'd to confirm that behavior.

Oddly enough, if I set this, the class takes effect:

<a [ngClass]="{'sortList' : true }">Some link</a>

So, in essence, it's refusing to recognize a variable I've set on my component, but I have no idea why. Any guesses?

尝试这个...

[ngClass]="{'aside': true, 'links': message === 'NORMAL', 'links2' : message === 'LIGHT'}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM