AngularJS – append row after element in directive

angularjs, angularjs-directive, angularjs-ng-repeat

Solution

This does the job:

app.directive('createTable', function ($compile) {
    return {
        link: function(scope, element, attrs) {
            if (element.next().length) {
                element.next().insertBefore(element);
            }

            var contentTr = angular.element('<tr><td>test</td></tr>');
            contentTr.insertAfter(element);
            $compile(contentTr)(scope);
        }
    }
});

http://jsfiddle.net/3gt9J/3/

Problem

My question is similar as this one, but instead of prepending row, I want it to append. This doesn’t work: ``` app.directive('createTable', function ($compile) { return { link: function (scope, element, attrs) { var contentTr = angular.element('<tr><td>test</td></tr>'); contentTr.parentNode.insertBefore(element, contentTr.nextSibling); $compile(contentTr)(scope); } } }); ```

Original source

Related problems