Angular指令的编写

directive()的第二个参数,传入$compile参数的情况

angular.module('name1').directive('directiveName', function($compile) {  
    return{
        restrict: 'E',
        scope: {},
        link:function(scope,element,attrs){        
            //一些DOM操作
            
            $compile(element.contents())(scope.$parent); //疑点 
        }
    }
}

疑点:$compile()()的作用及用法

希望大家能帮帮忙


UYOU
浏览 541回答 1
1回答

慕盖茨4494581

参考:$compile官方文档Compile的细节作用其实就是:Compiles an HTML string or DOM into a template and produces a template function, which can then be used to link scope and the template together.你提问里的用法其实就是ng提供的一种动态编译方法,实际就是起到了上述的作用。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript