destroy directive/child scope on scope destroy

前端 未结 1 938
说谎
说谎 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: '<div >Child Directive</div>',                
            link: function(scope, element){                  
                scope.$on("$destroy",function() {
                    element.remove();
                }); 
            }
        }
    });
    

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

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