SO - 18483324
by michiganfootball20
HTML
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js"></script>
<table >
<tbody>
<tr ng-repeat="row in rows" create-table row-data="row">
<td>{{row.title}}</td>
</tr>
</tbody>
</table>
JavaScript
var app = angular.module('my-app', [], function () {
})
app.controller('AppController', function ($scope) {
$scope.message = "Welcome";
$scope.rows = [{
title: 'One',
child: [{
title: 'One - child'
}, {
title: 'Two - child'
}]
}, {
title: 'Two'
}];
});
app.directive('createTable', function ($compile) {
return {
scope: {
rowData: '='
},
link: function (scope, element, attrs) {
if (element.next().length) {
element.next().insertBefore(element);
}
/*
if (scope.row.child) {
var contentTr = angular.element('<tr><td>{{row.title}}</td></tr>');
contentTr.insertAfter(element);
$compile(contentTr)(scope);
}*/
}
}
});