Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何包括<;tr>;角度指令中的元素(transclude)?_Javascript_Html_Angularjs - Fatal编程技术网

Javascript 如何包括<;tr>;角度指令中的元素(transclude)?

Javascript 如何包括<;tr>;角度指令中的元素(transclude)?,javascript,html,angularjs,Javascript,Html,Angularjs,我想包括和,显然我不能用指令来实现这一点。它一直忽略或,就好像它们不存在一样。以下是我试图实现的目标: <my-table> <tr> <td>hello</td> <td>world</td> </tr> </my-table> my-table.html: <table ng-transclude> </table> 上述代码导致:

我想包括
,显然我不能用指令来实现这一点。它一直忽略
,就好像它们不存在一样。以下是我试图实现的目标:

<my-table>
   <tr>
     <td>hello</td>
     <td>world</td>
   </tr>
</my-table>
my-table.html:

<table ng-transclude>

</table>

上述代码导致:

<my-table class="ng-isolate-scope"><table ng-transclude="">

   hello  <-- no <tr> nor <td> here just plain text
   world

</table></my-table>


您好这不是一个排除问题。无效html有一个问题,因为没有表的
是无效的。所以angular是从浏览器
文本
获取的,而不是DOM元素。因此,在html中需要有
标记:

  <my-table>
  <table>
      <tr>
       <td>hello</td>
       <td>world</td>
     </tr>
  </table>
  </my-table>

或者像以前一样在模板中使用
ng transclude
。但是,我可能认为您以后会希望重用转置的部分,因此在链接函数中访问它对我来说更有意义。

将前面的注释添加到我的注释中,如果您希望使用ng trasclude,您可以实现类似的效果

angular.module('app', [])
  .controller('Controller', ['$scope', function($scope) {

  }])
  .directive('myTable', function() {
    return {
      restrict: 'E',
      transclude: true,
      scope: {
        'close': '&onClose'
      },
      templateUrl: 'my-dialog-close.html'
    };
  });
模板

index.html

<my-table>
    <table>
     <tr>
       <td>hello</td>
       <td>world</td>
     </tr>
    </table>
  </my-table>

你好
世界

Plunker:

那些
应该放在
我的对话框close.html
@RogerNg中,这正是我不想要的。我想要一个可定制的
,但我希望它由我的指令包装。将其作为
的替代图像,没有该表的tr将是无效的html。这就是为什么它把它作为一个文本bt而不是HTMLH来总结,这就是为什么我以前在我的plunkr代码中得到警告。非常感谢。
angular.module('app', [])
  .controller('Controller', ['$scope', function($scope) {

  }])
  .directive('myTable', function() {
    return {
      restrict: 'E',
      transclude: true,
      scope: {
        'close': '&onClose'
      },
      templateUrl: 'my-dialog-close.html'
    };
  });
<my-table>
    <table>
     <tr>
       <td>hello</td>
       <td>world</td>
     </tr>
    </table>
  </my-table>