Transclude会删除tr和td标签吗?

时间:2019-08-22 06:55:11

标签: javascript angularjs

我有以下angularjs应用程序,但是由于某种原因,tr和td标签被删除了?

angular.module('transcludeExample', [])
  .directive('pane', function() {
    return {
      restrict: 'E',
      transclude: true,
      scope: {
        title: '@'
      },
      replace: true,
      template: '<table><tbody ng-transclude></tbody></table>'
    };
  })
  .controller('ExampleController', ['$scope', function($scope) {}]);
td {
  background: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.8/angular.min.js"></script>
<div ng-controller="ExampleController">
  pre
  <pane>
    <tr>
      <td><strong>testtest</strong></td>
    </tr>
  </pane>
  post
</div>

1 个答案:

答案 0 :(得分:1)

似乎浏览器会忽略此html代码,因为最初缺少<table>标签(因此它仅显示文本):

 <tr>
  <td><strong>testtest</strong></td>
</tr>

我认为唯一的解决方案是将ng-transclude移到外部元素,而不是拆分表标签。例如:jsfiddle example

相关问题