Ng-repeat datas from 2 json Angular

為{幸葍}努か 提交于 2019-12-25 16:58:20

问题


I try to get data from 2 jsons and list it in table :

1st 'names.json':

[
        {
            "name": "AAAAAA",
            "down": "False"

        },

        {
            "name": "BBBBBB",
            "down": "45%"
        },
        {
            "name": "CCCCC",
            "down": "12%"
        }
]

Second 'data.json'

[
         {
            "data": "25-12-2014"
        }
]

Javascript:

 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 must show it in table HTML :

div ng-controller="FirstCtrl"
     <table>
        <tbody>
          <tr ng-repeat="name in names.concat(datas)">
            <td>{{name.name}}</td>
            <td>{{name.data}}</td>
          </tr>
        </tbody>
      </table>
    </div>

I try concat() but it dont work, is there any method to show in table datas from 2 arrays by ng-repeat? Thanks for answers in advance!

来源:https://stackoverflow.com/questions/41674695/ng-repeat-datas-from-2-json-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!