Angularjs:$范围VS范围 [英] Angularjs: $scope vs scope
问题描述
在Angularjs,有没有使用控制器 $范围
和范围
(不包括<$ C特殊原因$ C>$)的指令链接功能?难道仅仅是一个约定,或者别的什么吗?
In Angularjs, is there a specific reason to use $scope
in controllers and scope
(without "$"
) in directives link function? Is it just a convention or anything else?
推荐答案
当你做 $范围
在控制器中的依赖注入注入基于匹配变量名范围的情况下, $范围
,在这种情况下使用范围
姓名是行不通的。
The case when you do $scope
in controller the Dependency Injection injects scope based on matching the variable name $scope
, in this case using scope
as name would not work.
有关指令的情况下,注射位置,并根据这样你就可以命名你的变量 A
或 B
或任何东西。对于链接功能的指令顺序为
For case of directive the injection is position based so you can name your variable a
or b
or any thing. The directive order for link function is
(范围,iElement,iAttrs控制器)
所以第一个元素总是范围对象。
so first element is always scope object.
这篇关于Angularjs:$范围VS范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!