为了账号安全,请及时绑定邮箱和手机立即绑定

Angular指令的编写

Angular指令的编写

UYOU 2018-09-03 13:13:21
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()()的作用及用法希望大家能帮帮忙
查看完整描述

1 回答

?
慕盖茨4494581

TA贡献1850条经验 获得超11个赞

参考:
$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提供的一种动态编译方法,实际就是起到了上述的作用。


查看完整回答
反对 回复 2018-10-08
  • 1 回答
  • 0 关注
  • 539 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信