Phu Nguyen Phu Nguyen - 1 month ago 22
AngularJS Question

Ng-repeat within an ng-repeat-start



My data:

$scope.members = [
{
projects: [...]
},
{
projects: [...]
}, ...
] // $scope.members.length == 15


My code:

<tr>
<th ng-repeat-start="member in members" ng-repeat="project in member.projects" ng-repeat-end ng-if="member.projects" >
{{project.name}}
</th >
</tr>


No element is generated. I checked the Elements in Chrome developer tool, and I found these in the
<tr>
tag comments like this:

<!-- ngRepeat: member in members -->

<!-- ngRepeat: member in members -->
<!-- end ngRepeat: member in members --> (x30)


I also tried this:

<tr ng-repeat-start="member in members">
<th ng-repeat="project in member.projects" ng-repeat-end ng-if="member.projects" >
{{project.name}}
</th >
</tr>


But then I have the error:
Unterminated attribute, found 'ng-repeat-start' but no matching 'ng-repeat-end' found.


Does anyone have an idea? Thanks in advance.

Answer

Updated answer:

Get only the 'projects' arrays into a new array, like so:

$scope.projectsOnly = [];//empty array
$scope.members.forEach(function(item){
        $scope.projectsOnly.push(item.projects);
})

and then loop only into that array, like so:

<tr>
    <th ng-repeat="project in projectsOnly " >
        {{project.name}}
    </th >
</tr>

Hope helps, good luck.