Reputation: 167
Im getting following json and want to repeat and bind the value
but its seems something wrong.
JSON
{
"1428394433116":[
{
"path":"path0","value":"test path 2"
},
{
"path":"path1","value":"test path 1"
}
],
"1428467596813":[
{
"path":"path0","value":"path info 1"
},
{
"path":"path1","value":"path info 2"
},
{
"path":"path2","value":"path info 3"
}
] }
ng-repeater
<p ng-repeat="p in ps">
<label>Path <span ng-bind="$index"></span> :</label>
<span class="normal-f">
<span ng-bind="p.value"></span>
<input type="text" ng-model="a.path[$index]">
</span>
</p>
Update
Thanks, ID-1428394433116 for one module and ID-1428467596813 for another module.
So expected result is:
path 1: test path 2
path 2: test path 1
Upvotes: 0
Views: 229
Reputation: 1879
Here the JSON data contains another JSON data.
So '1428394433116' contains one set of data or JSON and '1428467596813' contains another set of JSON. So you require to use ps.1428394433116 and ps.1428467596813 separately to get value.
Upvotes: 0
Reputation: 1398
You try to bind an Array as String on this Line <span ng-bind="p.value"></span>
p.value
does not exist, because p
is an Array.
The first p
shoud look like this:
[
{
"path":"path0","value":"test path 2"
},
{
"path":"path1","value":"test path 1"
}
]
You have to use another ngRepeat
for p
or you have to use the first Element everytime like this <span ng-bind="p[0].value"></span>
that means the best method shoud look like this:
<p ng-repeat="(ID, p) in ps"><!-- here you get the index (ID) and the Array (p) -->
<label>Path <span ng-bind="ID"></span> :</label>
<span ng-repeat="element in p track by $index" class="normal-f"><!-- here comes the other repeat -->
<span ng-bind="element.value"></span>
<input type="text" ng-model="a.path[$index]">
</span>
</p>
Upvotes: 1