What is the default scope value of an AngularJS directive?
AngularJS指令的默认范围值是多少?
Of course, it is not isolated scope. It is true or false.
当然,它不是孤立的范围。这是真的还是假的。
I can't find any documentation on what it is.
我找不到任何关于它的文件。
2 个解决方案
#1
21
"Note, by default, directives do not create new scope -- i.e., the default is
scope: false
"注意,默认情况下,指令不会创建新的范围——例如。,默认是作用域:false"
from Understanding scopes.
从理解范围。
Using the scope option in directive you can:
使用指示中的范围选项,你可以:
- create a child scope prototypically inherited with
scope: true
- 创建一个典型继承的子范围原型:true。
- create an isolated scope with
scope: {}
then you can bind some property to parent scopes with'@', '&', '='
(see this question). - 创建一个具有scope:{}的隔离范围,然后您可以使用'@'、'&'、'='将一些属性绑定到父范围(请参见这个问题)。
- decide to not create a new scope and use parent with
scope: false
(default). - 决定不创建新范围并使用scope: false(默认)的父范围。
#2
0
By default, directives shared the scope of the containing controller. You can specify scope:true
to have a inherited scope and to get a isolated scope you have to do the following
默认情况下,指令共享包含控制器的范围。您可以指定scope:true来拥有一个继承的范围,要获得一个独立的范围,您必须执行以下操作
scope:{
something1:"@",
something2:"="
something3:"&"
}
#1
21
"Note, by default, directives do not create new scope -- i.e., the default is
scope: false
"注意,默认情况下,指令不会创建新的范围——例如。,默认是作用域:false"
from Understanding scopes.
从理解范围。
Using the scope option in directive you can:
使用指示中的范围选项,你可以:
- create a child scope prototypically inherited with
scope: true
- 创建一个典型继承的子范围原型:true。
- create an isolated scope with
scope: {}
then you can bind some property to parent scopes with'@', '&', '='
(see this question). - 创建一个具有scope:{}的隔离范围,然后您可以使用'@'、'&'、'='将一些属性绑定到父范围(请参见这个问题)。
- decide to not create a new scope and use parent with
scope: false
(default). - 决定不创建新范围并使用scope: false(默认)的父范围。
#2
0
By default, directives shared the scope of the containing controller. You can specify scope:true
to have a inherited scope and to get a isolated scope you have to do the following
默认情况下,指令共享包含控制器的范围。您可以指定scope:true来拥有一个继承的范围,要获得一个独立的范围,您必须执行以下操作
scope:{
something1:"@",
something2:"="
something3:"&"
}