通过'模板'指令添加的行被添加到表的顶部?

时间:2016-08-31 06:17:17

标签: angularjs templates directive

代码的呈现方式如下: -

指令的模板位于顶部,然后正在渲染thead,但是thead应该位于顶部。

这是HTML

 <div class="panel_content">
    <table summary="A table listing various other formats for this product">
      <thead>
        <tr>
          <th scope="col">Other Formats</th>
          <th scope="col" class="site amount"><span>price</span></th>
          <th scope="col" class="market_place amount"><span>New from</span></th>
          <th scope="col" class="market_place amount"><span>Used from</span></th>
          <th scope="col" class="market_place amount"><span></span></th>
          <th scope="col" class="market_place amount"><span></span></th>
        </tr>
      </thead>
      <tbody>
          <dir></dir>
      </tbody>
    </table>
  </div>

这是指令

app.directive('dir', function() {
            return {
              restrict: 'E',
              replace: true,
              template: '<tr><td>asdf</td></tr>'
            };
});

1 个答案:

答案 0 :(得分:2)

tbody不期望您的指令dir标记(期望tr)。尝试修改代码:

app.directive('dir', function() {
            return {
              restrict: 'A',
              replace: true,
              template: '<tr><td>asdf</td></tr>'
            };
});

并使用

<tbody>
    <tr dir></tr>
</tbody>