0

I want to change the colors of my cell, so in my table i do this on my td

data-ng-class="{selected.id == price.id && !price.isMinPrice ? 'selected' : '', selected.id == price.id && price.isMinPrice ? 'minSelected' : ''}" 

i have this error:

Error: [$parse:syntax] Syntax Error: Token '.' is unexpected, expecting [:] at column 10 of the expression [{selected.id == price.id && !price.isMinPrice ? 'selected' : '', selected.id == price.id && price.isMinPrice ? 'minSelected' : ''}] starting at [.id == price.id && !price.isMinPrice ? 'selected' : '', selected.id == price.id && price.isMinPrice ? 'minSelected' : ''}].

What is wrong ..?

0

2 Answers 2

2

You are using ng-class all wrong and that is why you are getting syntax errors.

You need to give it an object literal:

data-ng-class="{selected: selected.id == price.id && !price.isMinPrice, minSelected: selected.id == price.id && price.isMinPrice}" 

This is also much cleaner than what you were trying to do.

Sign up to request clarification or add additional context in comments.

Comments

1

I think that ng-class expects structure like this: {'class-name' : booleanValue}, and if value is true, class will be applied.

So in your case:

data-ng-class="{'selected' : selected.id == price.id && !price.isMinPrice, 'minSelected' : selected.id == price.id && price.isMinPrice}"

and if you want to use ternaty operator, you can use class attribute with {{}}:

class="{{selected.id == price.id && !price.isMinPrice ? 'selected' : ''}}"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.