如何显示循环后的所有多数据数组,并显示所有数据与ng-repeat?

嘿,我所有的我的代码有一些麻烦,首先我想告诉我的代码后,我发现像这样的数据:
1. apifind

var Group = require('../models/group/GroupAlm.js'); var fs = require('fs'); module.exports = function(groupalm) { groupalm.get('/groupalm/:nim', function(req, res){ var getOne = req.params.nim; Group.find({ nim:getOne}).select('postings').exec(function(err, grooup){ if (err){ res.json({ success: false, message: 'Not Found'}); }else{ res.json({ success:true, grooup:grooup}); } }) });return groupalm;}; 

和2.呼叫获得API

 var appFactory=angular.module('app.factory',[]); appFactory.factory('AllGrp',function($http){ var allNotFactory = {}; allNotFactory.getAllAlmGrp = function(nim) { return $http.get('/mod_mygroup/groupalm/' + nim); }; return allNotFactory; }); 

3是我的控制器

 app.controller('appCtrl', ['$scope','AllGrp', function ($scope,AllGrp) { function getGroupByPKNIMalm() { var nim = 11037050017; AllGrp.getAllAlmGrp(nim).then(function(cek){ if (cek.data.success){ for (var i = 0; i < cek.data.grooup.length; i++){ $scope.grp = cek.data.grooup[i].postings; console.log('data',$scope.grp); } }else{ console.log('err');} }); }; getGroupByPKNIMalm(); }]); 

更新文本HTML这个ng-repeat显示数据

 <li class="list-group" role="presentation" ng-repeat="groups in grp | orderBy:'created_at':true "> <div data-role="container"> <div data-role="content"> <a class="list-group-item" href="javascript:void(0)" role="menuitem"> <div class="media"> <div class="media-left padding-right-10"> <i class="icon md-receipt bg-red-600 white icon-circle" aria-hidden="true"></i> </div> <div class="media-body"> <h6 class="media-heading">{{groups.nim}}</h6> <h6 class="media-meta">{{groups.post}}</h6> </div> </div> </a> 

/结束更新文本HTML /

okey在步骤1-3是成功从api获取数据,这是我的数据get / Find后:

 { "success": true, "grooup": [ { "_id": "59eeb992a6ddc00f1037c1cf", "postings": [ { "nim": 1137050017, "nama": "ADRIYANA PUTRA PRATAMA", "post": "hay salam kenal", "created_at": "2017-10-24T03:55:17.004Z" }, { "nim": 1111111, "nama": "Fakih Nuzli", "post": "hay salam kenal", "created_at": "2017-10-24T04:01:14.954Z" } ] }, { "_id": "59ef26cc0cfb2618d047cc6f", "postings": [ { "nim": 1137050017, "nama": "ADRIYANA PUTRA PRATAMA", "post": "selata datang", "created_at": "2017-10-24T21:27:06.091Z" }, { "nim": 1111111, "nama": "Fakih Nuzli", "post": "ya thanx", "created_at": "2017-10-24T21:27:29.384Z" }, ] }, { "_id": "59e53fcd1e85242ea417832e", "postings": [ { "nim": 1111111, "nama": "Fakih Nuzli", "post": "hay", "created_at": "2017-10-24T11:19:44.318Z" } ], } ]} 

oke问题是在步骤3中,我在控制器中循环数据,为显示所有数据postings ,回头看第3步,有这样的循环数据代码循环代码

 for (var i = 0; i < cek.data.grooup.length; i++){ $scope.grp = cek.data.grooup[i].postings; console.log('data',$scope.grp); } 

代码在那里成功显示数据postings我看在console.log ,但后我ng-repeat="groups in grp" ,我试图显示所有posting {{groups.nim}} and {{groups.post}} 为什么他只是在最后的ID 59ef26cc0cfb2618d047cc6f显示数据发布。
那么如何显示所有的数据发布呢? 在循环之后,我从api Group.find({nim})获取数据。 谢谢 ;)

你需要合并来自每个post的数组,如下所示,

  $scope.grp.push( ...$scope.result.grooup[i].postings); 

DEMO

 var app = angular.module('testApp',[]); app.controller('testCtrl',function($scope){ $scope.grp=[]; $scope.result = { "success": true, "grooup": [ { "_id": "59eeb992a6ddc00f1037c1cf", "postings": [ { "nim": 1137050017, "nama": "ADRIYANA PUTRA PRATAMA", "post": "hay salam kenal", "created_at": "2017-10-24T03:55:17.004Z" }, { "nim": 1111111, "nama": "Fakih Nuzli", "post": "hay salam kenal", "created_at": "2017-10-24T04:01:14.954Z" } ] }, { "_id": "59ef26cc0cfb2618d047cc6f", "postings": [ { "nim": 1137050017, "nama": "ADRIYANA PUTRA PRATAMA", "post": "selata datang", "created_at": "2017-10-24T21:27:06.091Z" }, { "nim": 1111111, "nama": "Fakih Nuzli", "post": "ya thanx", "created_at": "2017-10-24T21:27:29.384Z" } ] }, { "_id": "59e53fcd1e85242ea417832e", "postings": [ { "nim": 1111111, "nama": "Fakih Nuzli", "post": "hay", "created_at": "2017-10-24T11:19:44.318Z" } ] } ]}; for (var i = 0; i < $scope.result.grooup.length; i++){ $scope.grp.push( ...$scope.result.grooup[i].postings); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <body ng-app="testApp" ng-controller="testCtrl"> <li class="list-group" role="presentation" ng-repeat="groups in grp | orderBy:'created_at':true "> <h6 class="media-heading">{{groups.nim}}</h6> <h6 class="media-meta">{{groups.post}}</h6> </li> </body>