angular compile vs link vs controller
2015-10-08 10:06
696 查看
compile function - use for template DOM manipulation (i.e., manipulation of tElement = template element), hence manipulations that apply to all
DOM clones of the template associated with the directive. (If you also need a link function (or pre and post link functions), and you defined a compile function, the compile function must return the link function(s) because the
is ignored if the
is defined.)
link function - normally use for registering DOM listeners (i.e.,
on the scope) as well as updating the DOM (i.e., manipulation of iElement = individual instance element). It is executed after the template has been cloned -- e.g., inside an
(tElement) has been cloned (into an iElement) for that particular
A
a directive to be notified of scope property changes (a scope is associated with each instance), which allows the directive to render an updated instance value to the DOM.
controller function - must be used when another directive needs to interact with this directive. E.g., on the AngularJS home page,
the pane directive needs to add itself to the scope maintained by the tabs directive, hence the tabs directive needs to define a controller method (think API) that the pane directive can access/call.
DOM clones of the template associated with the directive. (If you also need a link function (or pre and post link functions), and you defined a compile function, the compile function must return the link function(s) because the
'link'attribute
is ignored if the
'compile'attribute
is defined.)
link function - normally use for registering DOM listeners (i.e.,
$watchexpressions
on the scope) as well as updating the DOM (i.e., manipulation of iElement = individual instance element). It is executed after the template has been cloned -- e.g., inside an
<li ng-repeat...>, the link function is executed after the
<li>template
(tElement) has been cloned (into an iElement) for that particular
<li>element.
A
$watchallows
a directive to be notified of scope property changes (a scope is associated with each instance), which allows the directive to render an updated instance value to the DOM.
controller function - must be used when another directive needs to interact with this directive. E.g., on the AngularJS home page,
the pane directive needs to add itself to the scope maintained by the tabs directive, hence the tabs directive needs to define a controller method (think API) that the pane directive can access/call.
相关文章推荐
- AngularJS指南文档
- angular-2
- angular
- ionic小demo阶段性理解
- AngularJs controller出错的问题
- angularjs从零开始(一)
- angular debug 调试
- 学习笔记-AngularJs(九)
- angularjs基本理解
- AngularJS 指令之 ng-style
- AngularJS 指令之 ng-if
- Angularjs自定义过滤器
- angularjs 2.x 学习
- Angularjs登陆-Form测试
- angularjs路由例子
- 使用 angular-async-loader 来实现异步加载 angular 模块
- AngularJS 提交表单的方式(一)
- AngularJS动态设置CSS
- AngularJS一个由于未声明对象而报的错
- AngularJS双向绑定,手动实施观察