Lets say I've got a collapsible menu with two buttons that will display their corresponding content when clicked. If one is opened, it should close when the other button is clicked. I want to repeat this content x number of times.
<div *ngFor="let item of array; let i = index" class="container" id="myGroup">
<p>
<a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
content 1
</a>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample2" aria-expanded="false" aria-controls="collapseExample2">
Content 2
</button>
</p>
<div class="collapse" id="collapseExample" data-parent="#myGroup">
<div class="card card-body">
Content 1 here
</div>
</div>
<div class="collapse" id="collapseExample2" data-parent="#myGroup">
<div class="card card-body">
Content 2 here
</div>
</div>
</div>
I want each of divs
with the class container
to have their own unique id
to match with its content's data-parent
attribute. Something like this:
<div *ngFor="let item of array; let i = index" class="container" id="myGroup{{i}}">
<p>
<a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
content 1
</a>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample2" aria-expanded="false" aria-controls="collapseExample2">
Content 2
</button>
</p>
<div class="collapse" id="collapseExample" data-parent="#myGroup{{i}}">
<div class="card card-body">
Content 1 here
</div>
</div>
<div class="collapse" id="collapseExample2" data-parent="#myGroup{{i}}">
<div class="card card-body">
Content 2 here
</div>
</div>
</div>
My goal is to create a couple of buttons that I can print to the page x number of times. Each time a new set is printed to the page, it's buttons will only respond to its unique id
s and data-parent
s. I tried it just like what I included above, but got the following error:
Uncaught Error: Template parse errors:
Can't bind to 'parent' since it isn't a known property of 'div'.
Is this even possible? Any help is appreciated.