简体   繁体   中英

Accordion angularjs using bootstrap collapse

On my AngularJS app, I have a component <address> that use collapse from bootstrap. It was working perfectly until I tried to use a dynamic ID for the content to hide.

It was required since I'm using two <address> in the parent component, to avoid ID conflicts.

HTML sample :

<div ng-class="$ctrl.getAddressAccordionClass()">
    <h3 data-toggle="collapse" data-target="#$ctrl.addressId" ng-click="$ctrl.toggleAccordion();">
        <span>{{$ctrl.boxTitle}}</span>
    </h3>
    <div ng-attr-id="$ctrl.addressId" class="panel-collapse collapse in">
       <p>some content</p>
    </div>
</div>

I saw that I can use ng-attr-id to set a dynamic id. But how can I inject my id into data-target property ?

I asked too early the answer was simple, simply add double curly braces {{ }} :

<div ng-class="$ctrl.getAddressAccordionClass()">
    <h3 data-toggle="collapse" data-target="#{{$ctrl.addressId}}" ng- click="$ctrl.toggleAccordion();">
    <span>{{$ctrl.boxTitle}}</span>
</h3>
<div ng-attr-id="{{$ctrl.addressId}}" class="panel-collapse collapse in">
   <p>some content</p>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM