I know that this probably isn’t the cleanest/shortest solution but I can’t figure out why my ngClass isn’t styling the button correctly. It works fine if there are only 2 classes but when I go to 3 or 4 like in the above code it won’t change color based on the stored value…
Well, your first problem is that your first three if blocks reassign q1_readscore…
If that’s like…just a typo on here…when you inspect the element and look at the css classes applied how many are applied? My guess is one class is overriding the other.
Yeah the first class this.isReadingGold is overriding all of the others regardless of the value of q1_readscore.
I’m sure that I’ve done something dumb but I’m confused as to what you mean by the first three blocks reassigning q1_readscore?
I’m trying to check the value of q1_readscore and apply a single class depending on whether or not the value is 10, 9, 8, or less. It’s my first time using an ngClass that has more than 2 possibilities.
You are assigning 10 to readscore. This makes readscore 10. Every time this code block runs, readscore will be 10.
This has absolutely nothing to do with your class stuff and everything to do with you assigning 10 to readscore every time. I’d strongly recommend you use breakpoints and actually check the values of your variables when your code runs.
What I’m thought that I was doing after that was running conditionals that check IF the readscore = 10 THEN set the following classes, and so on for the other conditions.
The code works fine when I only have 2 classes such as in the following example: