这可能吗?我希望能够根据用户输入整理表主体,因此我只是将这个*测试一起进行了一次测试,看是否可行,但是由于表主体位于表主体的前面和外部,所以它会加载所有奇特的东西DOM,即使我将其适当地嵌套在html中。因此,我的问题是:1)这是什么一回事?和2)我可以实现我想要的方式吗?
的HTML:
<div ng-app="myApp" ng-controller="myController">
<table class="table">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<my-directive></my-directive><!-- this should be the tbody -->
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
</table>
</div>
js:
var app = angular.module("myApp", []);
app.directive("myDirective", function () {
return {
restrict: 'E',
template: '<tbody><tr><td>January</td><td>$100</td></tr><tr><td>February</td><td>$80</td></tr></tbody>',
};
});
当前,您正在<my-directive></my-directive>
元素中渲染标记,这使表格布局混乱。
而是将指令更改为基于属性的指令,然后将其放在<tbody>
元素上,以替换内容。
模板
</thead>
<tbody my-directive></tbody><!-- this should be the tbody -->
<tfoot>
指示
return {
restrict: 'A',
template: '<tr><td>January</td><td>$100</td></tr><tr><td>February</td><td>$80</td></tr>'
};
参见工作小提琴。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句