SO - 18483324

by sqiudward

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>
            <td nowrap ng-repeat="value in row">{{value}}</td>
        </tr>
    </tbody>
</table>

JavaScript

var app = angular.module('my-app', [], function () {

})

app.controller('AppController', function ($scope) {

    $scope.message = "Welcome";

    $scope.rows = [{
        title: 'One'
    }, {
        title: 'Two'
    }]
})

app.directive('createTable', function ($compile) {
    return {
        link: function(scope, element, attrs) {
            if (element.next().length) {
                element.next().insertBefore(element);
            }
            
            var contentTr = $('<tr><td>asa</td></tr>');
            var te = $('<span>AAAA</span>');
            contentTr.insertAfter(element);
            element.append(te);
            $compile(contentTr)(scope);
        }
    }
});