【问题标题】:Why angularjs' transclude causes cells separation (double borders) in a table?为什么 angularjs 的 transclude 会导致表格中的单元格分离(双边框)?
【发布时间】:2017-10-14 14:29:15
【问题描述】:

请参阅下面的指令,该指令将创建一个包含四列的表:

app.directive('tableWrapper',function() {
  return {
    restrict: 'E',
    transclude: true,
    template: '<table><ng-transclude></ng-transclude></table>',
  }
});

app.directive('myCells',function() {
  return {
    restrict: 'E',
    template: '<tr><td>Name</td><td ng-repeat="c in [1,2,3]">{{c}}</td></tr>',
  }
});

这里是 html(见 plunker:http://plnkr.co/edit/ZTrSifnYWKaNy9XQzfGL

<table><tr><td>Name</td><td ng-repeat="c in [1,2,3]">{{c}}</td></tr></table>
<hr/>
<table-wrapper><my-cells></my-cells></table-wrapper>

两者都在构建同一张表格,但第二张表格由于 transclude 的原因创建了单独的单元格。

所以代替:|名称|1|2|3|
第二个显示:|名称||1||2||3|
在哪里 ||是用相邻单元格的边框绘制的粗边框的文本表示。

这是什么原因?
有什么解决方法?

【问题讨论】:

    标签: css angularjs html-table cell


    【解决方案1】:

    transclude 'table' 没有border-collapse: collapse,因为它不匹配

    table{
        border-collapse: collapse
    }
    

    normalize.less中的规则

    如果您查看下面的 dom 结构,您就会明白原因。您的 transclude 'table' 实际上被呈现为 table-wrapper 元素而不是表格

    【讨论】:

    • 哇 - 为什么我的&lt;table&gt;&lt;/table&gt; 被带走了?!
    • 我明白了。我改用了&lt;table ng-transclude=""&gt;...&lt;/table&gt;,并且还在myCell 指令中添加了required: true。感谢您的帮助并将我引向那个答案!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多