destroy directive/child scope on scope destroy

前端 未结 1 939
说谎
说谎 2021-02-05 18:35

I have a directive that compiles another directive and attaches it to the body with the same scope passed. This will not be the same location as the \"parent\" directive.

1条回答
  •  失恋的感觉
    2021-02-05 19:24

    directive("childDirective", function(){
        return {
            restrict: 'C',              
            template: '
    Child Directive
    ', link: function(scope, element){ scope.$on("$destroy",function() { element.remove(); }); } } });

    updated fiddle : http://jsfiddle.net/C8hs6/

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