What is the default for AngularJS directive scope?

回眸只為那壹抹淺笑 提交于 2019-12-18 12:56:16

问题


What is the default scope value of an AngularJS directive?

Of course, it is not isolated scope. It is true or false.

I can't find any documentation on what it is.


回答1:


"Note, by default, directives do not create new scope -- i.e., the default is scope: false"

from Understanding scopes.

Using the scope option in directive you can:

  • create a child scope prototypically inherited with scope: true
  • create an isolated scope with scope: {} then you can bind some property to parent scopes with '@', '&', '=' (see this question).
  • decide to not create a new scope and use parent with scope: false (default).



回答2:


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:{
something1:"@",
something2:"="
something3:"&"
}


来源:https://stackoverflow.com/questions/22033354/what-is-the-default-for-angularjs-directive-scope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!