1

I want to use a collapse (from bootstrap) for each element from an array. So, I have an array extensions = ['firstCollapse', 'secondCollapse']. For each element I want to use a new collapse (there will be 2) and for this I iterate on the array, but I don't know how to modify the href to collapse each. Here is a part of code:

<div ng-repeat="ext in extensions">
   <div class="panel-group" id="accordion" ng-model="ext">
     <div class="panel panel-default">
       <div class="panel-heading">
         <h4 class="panel-title">
            <a data-toggle="collapse" data-parent="#accordion" href="#ext" ng-bind="ext"></a>
         </h4>
       </div>
     <div id="ext" class="panel-collapse collapse in">
        <div class="panel-body">
            Body
        </div>
      </div>
     </div>
    </div>
   </div>
  </div>

I tried to modify href according to current element from array but it didn't work. How can I make this possible? Thanks a lot.

2 Answers 2

1

You just need to use the double {{}} notation inside the href attribute.

EG:

<a href="{{'#' + ext}}">clicky</a>

Anything inside the {{}} will be evaluated as javascript on the current $scope.

Hope this helps.

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

Comments

1

Use ng-href instead of normal href

and wrap the ext (model) in brackets ( {{ext}} ) like this:

<a data-toggle="collapse" data-parent="#accordion" ng-href="#{{ext}}" ng-bind="ext"></a>

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.