1

How add a scope variable inside ng-class ? is it possible to combine ng-class and class together with scope variable ?

I am building an accordion. So I need to have unique "isopen" class, say isopne1, isopen2, etc.. for each accordion to work.

<accordion-heading>
  {{list.name}}<i class="pull-right glyphicon" ng-class="{'icon-arrow-down-solid': isopen, 'icon-arrow-right-solid': !isopen}"></i>
</accordion-heading>

The above code is in ng-repeat. How can I set something like this

ng-class="{'icon-arrow-down-solid': isopen{{list.value}}, 'icon-arrow-right-solid': !isopen{{list.value}}}"

2

3 Answers 3

1

Use scope function

ng-class="{'icon-arrow-down-solid': isopen(set.value), 'icon-arrow-right-solid': is_not_open(set.value)}"
Sign up to request clarification or add additional context in comments.

Comments

0
       <accordion close-others="oneAtATime">
        <accordion-group ng-repeat="set in sets" ng-init="status = $first" is-open="status" class="witlistcontents">
            <accordion-heading>
                Name <i class="pull-right glyphicon" ng-class="{'icon-arrow-down-solid': status, 'icon-arrow-right-solid': !status}"></i>
            </accordion-heading>
            <accordion-body>
            </accordion-body>
        </accordion-group>
       </accordion>  

Correct way to givie icon class for accordion inside ng-repeat

Comments

0

your code itself will work fine depending upon the scope variable (isOpen flag) you want to add the css class to the "i" element correct.Create a scope variable (isOpen flag) in the controller.Then depending upon the isOpen flag automatically the icon will change

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.