javascript - How can I repeat certain chunks of object with ng-repeat? -
i using angularjs mvc file structure. have data structure in controller want display on view. have custom "indicators" directive. each "title" belongs indicator , trying display group of 4 indicator elements @ time. using nested ng-repeats display 1 "chunk" of indicators @ time, browser console tells me wrong syntax of data structure or doesn't display @ all. works fine if indicators object has no "chunks" (nest) , 1 ng-repeat through object. have 2 questions:
- does know proper way of doing nested ng-repeats in context?
- is indicators object syntax wrong?
here indicators object in controller:
$scope.indicators = [{ "chunk1": {[ "ind1": { "title": 'ac', "active": true }, "ind2":{ "title": 'aux ps', "active": true }, "ind3":{ "title": 'main ps', "active": false }, "ind4": { "title": 'shutdown', "active": true } ]}, "chunk2": {[ "ind1": { "title": 'tx', "active": false }, "ind2": { "title": 'rx', "active": true } ]} }]; here part of view:
<div ng-repeat="chunks in indicators" > <div ng-repeat="ind in chunks"> <status-indicator title="ind.title" is-green="true" active="ind.active" ></status-indicator> </div> </div>
you json/object structure incorrect. should be:
[{ "chunk1": [{ "ind1": { "title": "ac", "active": true }, "ind2": { "title": "aux ps", "active": true }, "ind3": { "title": "main ps", "active": false }, "ind4": { "title": "shutdown", "active": true } }], "chunk2": [{ "ind1": { "title": "tx", "active": false }, "ind2": { "title": "rx", "active": true } }] }] swapped [] , {}
Comments
Post a Comment