AngularJS – 在指令中的元素后追加行 [英] AngularJS – append row after element in directive
本文介绍了AngularJS – 在指令中的元素后追加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题类似于这个,但我希望将其追加而不是添加行.
My question is similar as this one, but instead of prepending row, I want it to append.
这不起作用:
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);
}
}
});
推荐答案
这样做:
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);
}
}
});
这篇关于AngularJS – 在指令中的元素后追加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文