2

I am trying to create a template that shows some transcluded content. When I use ng-show everything works fine, but using ng-if or ng-switch gives me problems. I get this error message: Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found

I understand that ng-switch creates a new scope. But the transclude should still go up to the parent chain. Is this a defect in angularjs? See http://jsfiddle.net/HgvP7/

Here is my html, modified from the documentation example:

<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>

And the code:

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';
      }
    };
  });
user2957238
  • 121
  • 5
  • Well, it looks like you're not the only one with such a problem - https://github.com/angular/angular.js/issues/4969 . Really, I can't get it working. Looks like it really can't find the way up to directive. – ProdoElmit Nov 16 '13 at 03:02
  • possible duplicate of [Using ng-transclude inside ng-switch](http://stackoverflow.com/questions/19998934/using-ng-transclude-inside-ng-switch) – Paul Sweatte Jul 25 '15 at 03:21

0 Answers0