I have an angular application which uses an ng-repeat-start to display some dynamic information.
<div>
<table>
<tbody>
<tr my-directive ng-repeat="data in vm.data">
<td ng-bind="data.id"></td>
<td ng-bind="data.id"></td>
</tr>
<tr ng-repeat-end>
<td>extrarow</td>
</tr>
</tbody>
</table>
</div>
I also built a directive which I want to use to apply a class to the whole tr depending on the value of some of the data. I wanted to use link to do that instead of using a $watch.
As the itself can contain many inside, I wanted to use transclude to do this. I don´t want the tag to be inserted in my table as this breaks all my styles, so I have to do this manually, something like this:
function myDirective() {
return {
transclude: true,
scope: {},
link: function($scope, $element, $attrs, $ctrl, $transclude) {
var cloned = $transclude();
$element.append(cloned);
}
}
}
The problem is this is not working as expected. The cloned object is only being appended to the last row of the ng-repeat. It's probably due to the $element object, but I'm not sure about it.
I reproduced the problem in this jsfiddle.
Any ideas on where the problem is? Many thanks.