在带有transclude的指令中使用ng-switch

时间:2013-11-05 17:52:43

标签: angularjs

我正在尝试创建一个显示一些已删除内容的模板。当我使用ng-show时一切正常,但使用ng-if或ng-switch会给我带来麻烦。我收到此错误消息:在模板中非法使用ngTransclude指令!没有找到需要转换的父指令

据我所知,ng-switch创建了一个新的范围。但是转换仍然应该转移到母链。这是angularjs的缺陷吗?见http://jsfiddle.net/HgvP7/

这是我的html,从文档示例中修改:

<div ng-app="docsTransclusionExample">
  <div ng-controller="Ctrl">
    <my-dialog>Check out the contents, {{name}}!</my-dialog>
  </div>


  <!-- my-dialog.html -->
  <script type="text/ng-template" id="my-dialog.html">
    <div ng-switch="1+1">
        <div ng-switch-when="2">
            <div ng-transclude></div>
        </div>
    </div>
  </script>
</div>

代码:

angular.module('docsTransclusionExample', [])
  .controller('Ctrl', function($scope) {
    $scope.name = 'Tobias';
  })
  .directive('myDialog', function() {
    return {
      restrict: 'E',
      transclude: true,
      scope: {},
      templateUrl: 'my-dialog.html',
      link: function (scope, element) {
        scope.name = 'Jeff';
      }
    };
  });

0 个答案:

没有答案
相关问题