In the following code I am attempting to show a plus sign [+] for a series of regions. When the user clicks the plus sign the sub regions appear below AND the plus sign changes to a minus [-] sign.
The regions are displayed correctly and when the link is clicked the sub regions are displayed correctly. However, I cannot seem to get show/hide to work for the plus and minus and I need the sub regions to hide when the user clicks the minus to collapse the list again.
<div ng-repeat="item1 in vm.Regions track by $index">
{{item1}}
<a ng-click="vm.expandIt(item1)">
<span>[+]</span>
<span>[-]</span>
</a>
<input type="checkbox" />
<div ng-if="vm.collapseId==item1" ng-repeat="item2 in vm.data | filter:{'Region': item1}:true">
{{item2.CCG}}<input type="checkbox" ng-model="item2.Selected" />
</div>
</div>
The expandIt function looks like this:
function expandIt(item) {
vm.collapseId = item;
console.log(`expand called!:${vm.collapseId}`)
}
Can anyone please point me in the right direction?
Accordion. You can find many components already created. Also,ng-click="vm.expandIt(item1)should be on<span>[+]</span>and vice-versa on<span>[-]</span>ng-if="vm.collapseId==item1"(i guess only one region can be opened), you can try inexpandItfunction:vm.collapseId = (vm.collapseId == item) ? false : item;which will alternate the value if already set to this value