John Charger
John Charger

Reputation: 426

Appending rows to nested rows issue?

I'm making a table with nested row's.

The thing is that when I append a child row to a parent row all other parent rows append a child row also.

Use function:

$scope.templates=[{src:'template'}];
$scope.include = function(templateURI) {
   $scope.templates.push({src:templateURI});
 }

Append row:

<button class="btn btn-default btn-sm ng-scope" ng-click="include('rowInRow.html')">
    <i class="glyphicon glyphicon-upload"></i>
</button>

Show template:

<div ng-repeat="template in templates">
    <div ng-include="template.src">My template will be visible here</div>
</div>

Can somebody give me a hint? I tried to do it myself but I didn't find what I need.

Upvotes: 0

Views: 44

Answers (1)

Cameron
Cameron

Reputation: 434

Try this: http://plnkr.co/edit/ZzPF7UFjKyp2tqn27cf4?p=preview

All of the projects are sharing the templates collection. Solve this by giving each project its own templates array and iterating through that.

Make the include function into:

$scope.include = function(project, templateURI) {
  if (!project.templates)
    project.templates = [];
    project.templates.push({src:templateURI});
}

Call it like this:

<button class="btn btn-default btn-sm ng-scope" ng-click="include(project, 'rowInRow.html')">
  <i class="glyphicon glyphicon-upload"></i>
</button>

Show it like this:

<div ng-repeat="template in project.templates">
  <div ng-include="template.src">My template will be visible here</div>
</div>

Upvotes: 2

Related Questions