Is it possible to compile a modified directive template without using transclusion?

后端 未结 2 406
醉话见心
醉话见心 2021-01-06 11:15

I have been trying to use transclusion to create a directive which makes two copies of it\'s contents and appends them inside the original template. I have failed in my atte

相关标签:
2条回答
  • 2021-01-06 11:33

    I got your transcluded example working. See here.

    I had to call the below to get it working.

    $compile(clone)(scope.$parent);
    

    For the ngTransclude:orphan problem, in this version by compiling just the form elements it works when the child transclude is outside of the form.

    0 讨论(0)
  • 2021-01-06 11:43

    This plunker was prior to Angular 1.5 which introduce Tranclusion.

    link: function(scope, element) {
          if (!element.find('ng-transclude').children().length) {
            element.find('button').append('<b style="color: red">Button1</b>');
          }
        }
    

    Plunker

    0 讨论(0)
提交回复
热议问题