<table st-table="LIST_ITEMS" st-filtered-collection="filteredCollection" class="table table-striped ng-isolate-scope"> <thead> <tr> <th>Название</th> <th>Тип</th> <th>Індексация в БД </th> <th>Статус</th> <th>Страна</th> <th>Исходные данные</th> <th>Публикация Университета</th> <th>Автор сотрудник</th> <th>Соавторы студенти</th> <th>Публикация студента</th> <th>Соавторы других ВУЗов</th> <th>Соавторы заграничных ВУЗов</th> </tr> </thead> <tbody> <!-- ngRepeat: item in rests --><tr ng-repeat="item in rests" class="ng-scope"> <td ng-bind="item.job_title" class="ng-binding">Тестовая робота</td> <td ng-bind="item.types" class="ng-binding">учебник</td> <td ng-bind="item.indexing" class="ng-binding">да</td> <td ng-bind="item.status" class="ng-binding">национальный</td> <td ng-bind="item.country" class="ng-binding">Украина</td> <td ng-bind="item.output_data" class="ng-binding">тестовые</td> <td ng-bind="item.published_sumdu" class="ng-binding">да</td> <td> <span ng-bind="item.staff[$index].fio" class="ng-binding">PIB1</span> <br> <span ng-bind="item.staff[$index+1].fio" class="ng-binding">PIB2</span> </td> <td><span ng-bind="item.student[$index].fio" class="ng-binding">PIB1</span> <br> <span ng-bind="item.student[$index+1].fio" class="ng-binding">PIB2</span></td> <td ng-bind="item.student_publication" class="ng-binding">да</td> <td><span ng-bind="item.oi[$index].fio" class="ng-binding">PIB1</span> <br> <span ng-bind="item.oi[$index+1].fio" class="ng-binding">PIB2</span></td> <td><span ng-bind="item.fi[$index].fio" class="ng-binding">PIB1</span> <br> <span ng-bind="item.fi[$index+1].fio" class="ng-binding">PIB2</span></td> </tr><!-- end ngRepeat: item in rests --> </tbody> <tfoot> <tr> <td colspan="5" class="text-center"> <div st-pagination="" st-items-by-page="itemsByPage" st-displayed-pages="10" class="ng-isolate-scope"><!-- ngIf: numPages && pages.length >= 2 --></div> </td> </tr> </tfoot> </table> 

This is the interface itself, tried to output it through another ng-repeat, but then looked into the documentation again and realized that it cannot be used as a loop for nested objects, that is, like this:

 <tbody> <tr ng-repeat="item in rests"> <td ng-bind="item.job_title"></td> <td ng-bind="item.types">></td> <td ng-bind="item.indexing">></td> <td ng-bind="item.status">></td> <td ng-bind="item.country">></td> <td ng-bind="item.output_data">></td> <td ng-bind="item.published_univercity">></td> <td ng-repeat="item.staff in rests.item track by item.staff.id"> <span ng-bind="item.staff[$index].fio"></span> </td> <td ng-bind="item.student[$index].fio"></td> <td ng-bind="item.student_publication"></td> <td ng-bind="item.oi[$index].fio"></td> <td ng-bind="item.fi[$index].fio"></td> </tr> </tbody> 

How can one iterate over the loop and output only 1 property of objects or can it somehow be done when receiving data in the controller?

I will explain the data model: there is an essence “publication”, it has its own attributes, there are entities “student”, “employee”, “co-author of another university”, “co-author of a foreign university”. They are all related to the “publication” of the set-to-set relationship. When I output all the attributes of a publication, I want to put in 1 cell of the table, by the link, output all the names of the objects associated with it, which I received by rest api, and there may be a lot of them in one publication, that is: there will be a cycle for each object in the program, Now with an index in the interface (now output only by the 1st property) when displaying all the full names (these are nested / associated with the main object): ng-bind = "item.staff [$ index] .fio", ng-bind = "item. student [$ inde‌ x] .fio "B ng-bind =" item.oi [$ index] .fio ", ng-bind =" item.fi [$ index] .fio ".

An example of the data obtained in json:

 [ {"id":1,"job_title":"Тестовая робота","types":"учебник","indexing":"да","status":"национальный","country":"Украина","output_data":"тестовая","published_univercity":"да","student_publication":"да", "oi": [ {"id":1,"fio":"oi_pib1","name_oi":"name_oi_1"}, {"id":2,"fio":"oi_pib2","name_oi":"name_oi_2"} ], "staff": [ {"id":1,"fio":"PIB1","faculty":"ELIT","department":"computer science"}, {"id":2,"fio":"PIB2","faculty":"ELIT","department":"computer science"} ], "fi": [ {"id":1,"fio":"PIB1","name_fi":"name_fi"}, {"id":2,"fio":"PIB2","name_fi":"name_fi2"} ], "student": [ {"id":1,"fio":"S_PIB1","faculty":"elit","department":"computer science","groups":"it-01"}, {"id":2,"fio":"S_PIB2","faculty":"elit","department":"computer science","groups":"it-02"} ]}, ] 

I just tried to work and bring to mind only on the 1m embedded object. The controller is simple, here is a piece to get data from the server:

 'use strict'; var controllers = angular.module('controllers', []); controllers.controller('RestController', ['$scope', 'RestService', function ($scope, RestService) { $scope.rests = []; RestService.get().then(function (data) { if (data.status == 200) $scope.rests = data.data; }, function (err) { console.log(err); }); } ]); 
  • Comments are not intended for extended discussion; conversation moved to chat . - Nick Volynkin

2 answers 2

I tried to understand from the question and from the comments what the author of the question wanted, but did not understand why nested loops could not be used inside the cell. The html of the question looks the same. In the right direction I think:

 angular.module('app', []) .controller('Page', function() { this.data = [{"id": 1, "job_title": "Тестовая робота", "types": "учебник", "indexing": "да", "status": "национальный", "country": "Украина", "output_data": "тестовая", "published_univercity": "да", "student_publication": "да", "oi": [{"id": 1, "fio": "oi_pib1", "name_oi": "name_oi_1"}, {"id": 2, "fio": "oi_pib2", "name_oi": "name_oi_2"} ], "staff": [{"id": 1, "fio": "PIB1", "faculty": "ELIT", "department": "computer science"}, {"id": 2, "fio": "PIB2", "faculty": "ELIT", "department": "computer science"} ], "fi": [{"id": 1, "fio": "PIB1", "name_fi": "name_fi"}, {"id": 2, "fio": "PIB2", "name_fi": "name_fi2"} ], "student": [{"id": 1, "fio": "S_PIB1", "faculty": "elit", "department": "computer science", "groups": "it-01"}, {"id": 2, "fio": "S_PIB2", "faculty": "elit", "department": "computer science", "groups": "it-02"}]}]; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="app" ng-controller="Page as c"> <table border=1 st-table="LIST_ITEMS" st-filtered-collection="filteredCollection" class="table table-striped ng-isolate-scope"> <thead> <tr> <th>Название</th> <th>Тип</th> <th>Індексация в БД</th> <th>Статус</th> <th>Страна</th> <th>Исходные данные</th> <th>Публикация Университета</th> <th>Автор сотрудник</th> <th>Соавторы студенти</th> <th>Публикация студента</th> <th>Соавторы других ВУЗов</th> <th>Соавторы заграничных ВУЗов</th> </tr> </thead> <tbody> <tr ng-repeat="item in c.data" class="ng-scope"> <td ng-bind="item.job_title" class="ng-binding">Тестовая робота</td> <td ng-bind="item.types" class="ng-binding">учебник</td> <td ng-bind="item.indexing" class="ng-binding">да</td> <td ng-bind="item.status" class="ng-binding">национальный</td> <td ng-bind="item.country" class="ng-binding">Украина</td> <td ng-bind="item.output_data" class="ng-binding">тестовые</td> <td ng-bind="item.published_sumdu" class="ng-binding">да</td> <td> <div ng-repeat="sf in item.staff" ng-bind="sf.fio"></div> </td> <td> <div ng-repeat="st in item.student" ng-bind="st.fio"></div> </td> <td ng-bind="item.student_publication" class="ng-binding">да</td> <td> <div ng-repeat="o in item.oi" ng-bind="o.fio"></div> </td> <td> <div ng-repeat="f in item.fi" ng-bind="f.fio"></div> </td> </tr> </tbody> </table> </div> 

  • Thank you very much. Now I understand how the manipulations are carried out inside ng-repeat. - Eugene

Nested loops quite work for themselves:

 angular.module('app', []) .controller('Page', function() { this.data = [{"id": 1, "job_title": "Тестовая робота", "types": "учебник", "indexing": "да", "status": "национальный", "country": "Украина", "output_data": "тестовая", "published_univercity": "да", "student_publication": "да", "oi": [{"id": 1, "fio": "oi_pib1", "name_oi": "name_oi_1"}, {"id": 2, "fio": "oi_pib2", "name_oi": "name_oi_2"} ], "staff": [{"id": 1, "fio": "PIB1", "faculty": "ELIT", "department": "computer science"}, {"id": 2, "fio": "PIB2", "faculty": "ELIT", "department": "computer science"} ], "fi": [{"id": 1, "fio": "PIB1", "name_fi": "name_fi"}, {"id": 2, "fio": "PIB2", "name_fi": "name_fi2"} ], "student": [{"id": 1, "fio": "S_PIB1", "faculty": "elit", "department": "computer science", "groups": "it-01"}, {"id": 2, "fio": "S_PIB2", "faculty": "elit", "department": "computer science", "groups": "it-02"}]}]; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="app" ng-controller="Page as c"> <table border=1> <tr><th>job_title<th>fio<th>name</tr> <tr ng-repeat="item in c.data"> <td>{{item.job_title}}</td> <td> <div ng-repeat="subitem in item.oi"> {{subitem.fio}}, {{item.staff[$index].fio}} </div> </td> <td> <div ng-repeat="subitem in item.oi"> {{subitem.name_oi}}, {{item.fi[$index].name_fi}} </div> </td> </tr> </table </div> 

However , you need to be very careful when using such tricks:

  • The number of elements in the arrays must match (we use someone else's index)
  • Also must be the same sorting! Otherwise, elements belonging to different id will be in the same cell.
  • $index refers to the current (closest) ngRepeat , the parent index is accessed via the parent scope: $parent.$index . It is often not obvious (and after changing the code errors may occur), which particular cycle is $parent.$parent.$parent.$index , because not only ngRepeat generates scope. Such constructions should be avoided.
  • Strangely, this option does not work for me, it only outputs empty blocks. But thanks for the hint, I will try to move in this direction then. - Eugene
  • worth warning about accuracy when using nested loops and special like $index - Grundy
  • @Grundy, do I understand what you mean? (see last edit) Or not just about that? - vp_arth
  • @vp_arth, not only: $index refers directly to the nearest ng-repeat sometimes it may not be obvious - Grundy
  • not only ngRepeat what? :-D - Grundy