How to replace the element with ng-transclude

后端 未结 4 1220
名媛妹妹
名媛妹妹 2021-01-30 17:24

Is it possible to replace the element with ng-transclude on it rather than the entire template element?

HTML:

4条回答
  •  名媛妹妹
    2021-01-30 17:37

    I think the best solution would probably be to create your own transclude-replace directive that would handle this. But for a quick and dirty solution to your example you could essentially manually place the result of the transclusion where you want:

    my-transcluded-directive.html:

    I WILL BE REPLACED
    I will not be touched.

    Directive:

    return {
        restrict:'A',
        templateUrl:'templates/my-transcluded-directive.html',
        transclude:true,
        link:function(scope,element,attrs,ctrl, transclude)
        {
             element.find('span').replaceWith(transclude());
        }
    };
    

提交回复
热议问题