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);
}
}
});
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/
I think you need
app.directive('createTable', function ($compile) {
return {
link: function (scope, element, attrs) {
var contentTr = angular.element('<tr><td>test</td></tr>');
contentTr.insertAfter(element);
$compile(contentTr)(scope);
}
}
});
Demo: Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With