I am looking to display a structured list of layers and sublayers by looping through an object using ng-repeat.
var lyrslist = [
{ layername: "Base Maps", layertype: "layer" },
{ layername: "Open Street Map", layertype: "sublayer" },
{ layername: "Designated Sites", layertype: "layer" },
{ layername: "Ancient Woodlands", layertype: "sublayer" },
{ layername: "Conservation Areas", layertype: "sublayer" },
{ layername: "Listed Buildings", layertype: "sublayer" }
];
HTML
<h5>Layers</h5>
<ul ng-repeat="lyr in lyrslist">
<li ng-if="lyr.layertype === 'layer'" >
Layer {{lyr.layername}}
<ul>
<li ng-if="lyr.layertype === 'sublayer'">
Sub Layer {{lyr.layername}}
</li>
</ul>
</li>
</ul>
Currently, only the Layers are being listed. It appears that ng-repeat
is not cascading down to the next <ul>
. I attempted placing ng-repeat
inside the <ul>
tag but it displayed the entire list instead of just the desired sub-layers.
This is how I envision the final output:
Layers
- Layer Base Maps
- Sub Layer Open Street Map
- Layer Designated Sites
- Sub Layer Ancient Woodlands
- Sub Layer Conservation Areas
- Sub Layer Listed Buildings