14

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.

martoncsukas
  • 2,077
  • 20
  • 23
Aladdin Mhemed
  • 3,817
  • 9
  • 41
  • 56
  • 1
    Default value of the scope is same as of the element on which the directive is invoke – JQuery Guru Feb 26 '14 at 06:21
  • if I give no value to scope, will this create a new prototypically inherited scope? or will it use the scope of the element as its scope? – Aladdin Mhemed Feb 26 '14 at 06:26
  • @AladdinMhemed: No. If you give no value, the default is equivalent to setting `scope: false`, which means to not create a new scope (essentially, it will "use the scope of the element as its scope", as you said) – rinogo Sep 22 '16 at 18:40

2 Answers2

21

"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).
Community
  • 1
  • 1
glepretre
  • 8,154
  • 5
  • 43
  • 57
  • 2
    Would be nice if this were in their api docs (currently found at https://docs.angularjs.org/api/ng/service/$compile). – aaaaaa Nov 22 '14 at 02:22
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:{
something1:"@",
something2:"="
something3:"&"
}
gofr1
  • 15,741
  • 11
  • 42
  • 52
Debasish
  • 1
  • 1