#[NgClass] how to manege priority.

11 messages · Page 1 of 1 (latest)

topaz urchin
#

Hello friends i have a div with ngClass:

<div [ngClass]="myValue.length > 0 ? 'myClass1' : 'myClass2' ">
</div>

And its work fine, but in some point of my code, the variable "myValue" become null or empty, and in that point my application goes down because cant read length of undefined.

So... how can i make the "if" inside the ngClass to verify first if myValue isnt null, undefined or empty, before check if the length is > 0

jagged herald
topaz urchin
#

hi Rob! glad to see you!

#

what the ?? 0 means?

#

(?? 0)

jagged herald
#

It means "if myvalue?. is null-ish, then use the right hand side of ??, or zero in this case

topaz urchin
#

Wooow, i search a lot on google and nobody told me that, thanks RoB!!!

#

Its workiiiingggg Rooooooooooooooooob

#

i gonna finish it before the deadline!