1

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 ?

1 Answer 1

1

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>

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

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.