My goal is to extract data from two JSON files and present it in a table:
The first file 'names.json' contains:
[
{
"name": "AAAAAA",
"down": "False"
},
{
"name": "BBBBBB",
"down": "False"
},
{
"name": "CCCCC",
"down": "True"
}
]
The second file 'data.json' contains:
[
{
"data": "15%"
}
]
Javascript code:
app.service('service', function($http, $q){
this.getNames = function () {
var datas = $http.get('data,json', { cache: false});
var names = $http.get('names.json', { cache: false});
return $q.all([datas, names]);
};
});
app.controller('FirstCtrl', function($scope, service) {
var promise = service.getNames();
promise.then(function (data) {
$scope.names = data.names.data;
$scope.datas = data.datas.data;
});
Now I need to display this data in an HTML table:
<div ng-controller="FirstCtrl">
<table>
<tbody>
<tr ng-repeat="name in names.concat(datas)">
<td>{{name.name}}</td>
<td ng-if="name.down === 'False'">{{name.down}}</td>
<td ng-if="name.down !== 'False'">{{name.data}}</td>
<td>{{name.data}}</td>
</tr>
</tbody>
</table>
</div>
I have tried using concat() method but it didn't work. Is there any other way to display data from two arrays using ng-repeat in a table? Thank you for your help!