5

I have an element which its whole content could be transcluded. the transclusion is optional, so I can let its inner parts stay but an inner element be transcluded. Let's see it in action:

    <h4 class="modal-title" ng-transclude="title">
    Are you sure you want to remove this <span ng-transclude="innerType">good</span>
    </h4>

In directive definition I have:

    myApp.directive('confirmDeleteModal',function(){
    return {
        restrict:'E',
        transclude: {
           title:'?modalTitle',
           innerType:'?modalType',
        },
        templateUrl:'templates/confirm_delete_modal.html',
        scope: {
           obj:'=info',
        },
     }
   });

The HTML code would be so:

  <confirm-delete-modal info="goodToBeDeleted">
     <modal-type>good</modal-type>
  </confirm-delete-modal>

When I run my code, I get the following error: [ngTransclude:orphan].

What should I do? I am using AngularJS v1.5.8

4
  • Is tranclude set to true? See docs.angularjs.org/error/ngTransclude/orphan Commented Aug 11, 2016 at 7:41
  • @ZdenekHatak I have passed an object containing my slots so there is no need to set transclude to true, see Multi-slot transclusion in [API reference]docs.angularjs.org/api/ng/directive/ngTransclude Commented Aug 11, 2016 at 7:43
  • Can you provide HTML dom that call your directive ? And the complete configuration of your directive? And last thing, what version of angular do you use ? Because multi sloting is available since 1.5 Commented Aug 11, 2016 at 7:47
  • @Silvinus I made the changes Commented Aug 11, 2016 at 7:57

1 Answer 1

1

You use another directive ng-transclude in a fall back content of modal-title. But the ng-transclude become the "parent" of the span and doesn't provide transclusion function. I suggest to you to modify your directive and to use the method isSlotFilled to know if title is filled or not :

directive('confirmDeleteModal',function(){
return {
  restrict:'E',
  transclude: {
    title:'?modalTitle',
    innerType:'?modalType',
  },
  link: function(scope, elem, attrs, ctrl, trfn) {
    scope.titleFilled = trfn.isSlotFilled('title');
  },
  template:'<h4 class="modal-title" ng-transclude="title" ng-if="titleFilled"></h4>' +
           '<h4 class="modal-title" ng-if="!titleFilled">Are you sure you want to remove this <span ng-transclude="innerType">good</span></h4>',
  scope:{
      obj:'=info',
  }
 }
})

(https://plnkr.co/edit/k0RXLWbOvHdNc9WFpslz?p=preview)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.