I have this object:
[{
'name': '2015',
'section': '001',
'subsections': [{
subsection:'aa',
mainelements: ['cc','dd']
},{
subsection:'bb',
mainelements: ['ee','ff']
}]
}]
and I can display them in html
<body>
<button ng-click="new()">New</button>
<ul>
<li ng-repeat="audit in audits">
<span ng-hide="editing"><h5>{{audit.name}}</h5></span></br>
<input ng-show="editing" type="text" ng-model="audit.name" size="30" placeholder="add name here"></br>
<span ng-hide="editing">{{audit.section}}</span></br>
<input ng-show="editing" type="text" ng-model="audit.section" size="30" placeholder="add section here"></br>
<ul>
<li ng-repeat="subsection in audit.subsections">
<span ng-hide="editing">{{subsection.subsection}}</span></br>
<input ng-show="editing" type="text" ng-model="subsection.subsection" size="30" placeholder="add subsection here"></br>
<ul>
<li ng-repeat="mainelement in subsection.mainelements">
<span ng-hide="editing">{{mainelement}}</span></br>
<input ng-show="editing" type="text" ng-model="mainelement" size="30" placeholder="add mainelement here"></br>
</li>
</ul>
</li>
</ul>
<div id="buttons">
<button type="button" ng-hide="editing" ng-click="editing = true">Edit</button>
<button type="button" ng-show="editing" ng-click="editing = false">Save</button>
</div>
</li>
</ul>
</body>
But the problem is, I need all ng-model to be dynamic so that I can edit them separately. In this case, only audit.name and audit.section is dynamic. But subsection.subsection and main element are not.
When I do this:
$scope.logging = function(i) {
var editaudit = $scope.audits[i];
console.log(editaudit.name);
console.log(editaudit.section);
console.log(editaudit.subsections);
console.log(editaudit.subsections.mainelements);
}
and get this
[Log] 2015
[Log] market map
[Log] [{subsection: "aa", mainelements: ["cc", "dd"], $$hashKey: "object:9"}, {subsection: "bb", mainelements: ["ee", "ff"], $$hashKey: "object:10"}]
[Log] undefined
- I can I get all
ng-modelto be dynamic? - How to access to
mainelementwhich is an object inKey-valueform?
Update:
I managed to get all my elements to show up:
<!--Html -->
<ul>
<li class="bitcard" ng-repeat="subsection in audit.subsections">
<span ng-hide="editing">{{audit.subsections[$index].subsection}}</span></br>
<input ng-show="editing" type="text" ng-model="audit.subsections[$index].subsection" size="30" placeholder="add subsection here"></br>
<ul>
<li class="bitcard" ng-repeat="mainelements in audit.subsections[$index].mainelements">
<span ng-hide="editing">{{mainelements}}</span></br>
<input ng-show="editing" type="text" ng-model="mainelements" size="30" placeholder="add mainelement here"></br>
</li>
</ul>
</li>
</ul>
But now the issue is ng-model="mainelements" at the 5th last line is not unique. Is there a way to have second index like $index02 or other alternative ways to do this?
edit. It will be nice if you can suggest something more optimum.