angularjs - 替换表的 Angular 指令

标签 angularjs angularjs-directive

处理<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 中已被弃用,或者将在下一个版本中。

Updated Fiddle

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/

相关文章:

javascript - Angular 显示和隐藏多个元素

javascript - AngularJS ngRepeat within Directiving using a locally defined collection

javascript - AngularJS 创建虚拟指令

javascript - 创建一个获取每个数组项并整理它的 JavaScript 对象

javascript - ngTable - 服务器端分页 getData 错误

javascript - 在下拉指令中动态添加 ng-click

javascript - 确认密码自定义指令在 Angular 中不起作用

javascript - 如何在Angularjs中推迟img src url计算?

javascript - 单击时添加复选标记,删除所有其他标记

javascript - Angular $resource 调用未提供完整数据