【问题标题】:Ng-transclude with nested directives带有嵌套指令的 Ng-transclude
【发布时间】:2014-12-11 16:31:56
【问题描述】:

我正在使用 2 个指令,其中一个指令模板包含第二个指令。我想在第二个(嵌套)指令中使用ng-transclude。我怎样才能做到这一点? Here is a plnkr.

<body ng-app="transcludeExample">
<script>
  angular.module('transcludeExample', [])
   .directive('pane', function(){
       return {
       restrict: 'E',
       transclude: true,
       scope: { title:'@' },
       template: '<div style="border: 1px solid black;">' +
                '<div style="background-color: yellow">{{title}}</div>' +
                '<test></test>' +
                //'<ng-transclude></ng-transclude>' +
              '</div>'
       };
  })
  .directive('test', function(){
       return {
         restrict: 'E',
         transclude: true,
         template: '<div><ng-transclude></ng-transclude></div>'
       };
  })
  .controller('ExampleController', ['$scope', function($scope) {
      $scope.title = 'Lorem Ipsuma';
      $scope.text = 'Neque porro quisquam est qui dolorem ipsum quia dolor...';
  }]);
</script>
<div ng-controller="ExampleController">
  <input ng-model="title"> <br/>
  <textarea ng-model="text"></textarea> <br/><br/><br/><br/><br/><br/>

  <pane title="{{title}}">{{text}}</pane>
</div>
</body>

【问题讨论】:

标签: angularjs angularjs-ng-transclude


【解决方案1】:

不知道我是否遗漏了什么,但这似乎有效:

template: '<div style="border: 1px solid black;">' +
            '<div style="background-color: yellow">{{title}}</div>' +
            '<test><ng-transclude></ng-transclude></test>' +
          '</div>'

【讨论】:

  • 我在发布问题后不久就发现了这一点。谢谢!
猜你喜欢
  • 2014-10-26
  • 1970-01-01
  • 2015-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多