处理<table>
的指令是否有特殊规则? ?
我不知道为什么我无法创建一个指令来替换 <table>
.
我创建了一个 jsfiddle example ;
我正在查看 Angular 问题,但没有找到答案。 This discussion很有趣。
编辑
为什么要替换表?
真正的模板比较复杂,比如:
<div class="grid">
<div no-result-message="items"></div>
<table ng-transclude></table>
<div paging="items"></div>
</div>
此外,我想移动 ng-repeat
在这个指令中而不是在 tr
中直接;
最佳答案
从看这个SO Q&A如果您在指令定义中使用 restrict: 'A'
,您的运气可能会更好。虽然我不确定它会取代 table ,但我想不出你为什么要那样做。此外,我很确定在指令中替换元素的功能在 angular 中已被弃用,或者将在下一个版本中。
angular.module('myApp',[])
.controller('MyCtrl', function($scope){
$scope.items = [
{first: 'Foo', last: 'Bar'},
{first: 'Baz', last: 'Zox'},
];
})
.directive('grid', function() {
return {
restrict: 'A',
replace: true,
transclude: true,
template: '<table ng-transclude></table>'
};
});
关于angularjs - 替换表的 Angular 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31362526/