Answer the question
In order to leave comments, you need to log in
How to merge two ng-repeats into one model?
Hello! I'll try to explain briefly. We have two files:
obj.html:
<ul>
<li ng-repeat="object in obj.items" ng-model="obj.items">
<input type="text" value="{{ object }}">
</li>
</ul>
<ul>
<li class="{{ obj.opt.list_class }}" ng-repeat="object in obj.items">
{{ object }}
</li>
</ul>
<ul ng-model="SortCtrl.list2">
<li class="list-type-option" ng-repeat="obj in SortCtrl.list2" /*ng-show="SortCtrl.compareBlog(obj)"*/>
<div ng-include="SortCtrl.getObject(obj)"></div>
<div ng-include="SortCtrl.editObject(obj)"></div>
</li>
</ul>
self.getObject = function (obj) { return 'templates/' + obj.type + '/obj.html'; };
self.editObject = function (obj) { return 'templates/' + obj.type + '/con.html'; };
<p class="{{ obj.opt.class }}">{{ obj.opt.value }}</p>
<label>Text:</label><input type="text" ng-model="obj.opt.value" value="{{obj.opt.value}}">
Everything works as intended. Answer the question
In order to leave comments, you need to log in
Solution that helped: I
had to specify the model with the
obj.html index:
<ul>
<li ng-repeat="object in obj.items track by $index">
<input type="text" ng-model="obj.items[$index]">
</li>
</ul>
ng-include
The default
directive always creates an isolated scope. The best way to avoid this is to create separate directives for your elements, like object-view
and object-edit
. There, an isolated area will not be created if you do not specify it.
A faster but dirtier option is to make your own alternative ng-include
which does the same thing but doesn't isolate the area. There is an implementation here:
stackoverflow.com/a/17340138/1293168
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question