2

I have a variable with 4 possible values and i want to add a class for the first 3 variables and another for first 2 variables, also the requirement will some time change to one class for two possible value and another for other value

so if i give

<span ng-class="{'yes' : provisioned=='active',
    'yes': provisioned=='cannot_delete_edit',
    'no': provisioned=='cannot_delete_edit_upload',
    'no': provisioned=='inactive'}" class="flag">
</span>

it is not working how can i solve this

2 Answers 2

4

You should have each class listed only once:

<span ng-class="{'yes': provisioned=='active' || provisioned == 'cannot_delete_edit', 'no': provisioned=='cannot_delete_edit_upload' || provisioned=='inactive', 'flag': true}"></span>
Sign up to request clarification or add additional context in comments.

Comments

0

If your span has only two options, you can use this instead:

<span ng-class="(provisioned=='active' || provisioned == 'cannot_delete_edit') ?
                'yes' : 'no'">...</span>

But this still leaves hard-coded values in the HTML. Instead, I would recommend leaving the data in the controller:

$scope.provisioned = (provisioned=='active' || provisioned == 'cannot_delete_edit');

and then using

<span ng-class="provisioned ? 'yes' : 'no'">...</span>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.