Difference between child and isolated areas in directives

I tried to understand the areas in AngularJS directives. From what I collect, there are three types:

  • region inherited from the parent controller
  • child region ( scope: true)
  • isolated volume ( scope: {})

I understand the first one. Second, the "scope" is defined as:

an area prototyped from the parent controller

and "isolated scope" is defined as

scope specific to the directive and not inherited from the parent controller

In layman's terms, what exactly is the difference between a "child's area" and an "isolated area"? What are their respective use cases?

+4
source share
3 answers

Regarding the type of area used, here are some of the guidelines that I adhere to. This knowledge is also related to the search for a number of Angular and third-party directives.

Use the parent domain, if you just need to add some behavior to existing elements of the DOM, ng-click, ng-show, ng-classare good examples of this. These directives do not come with their own template user interface, but simply extend the behavior of the output html elements.

scope:true , . Angular , ng-repeat , $index. .

, scope:{}, , scope . . , , html, .

, https://github.com/angular/angular.js/wiki/Understanding-Scopes, .

, .

+4

, , , 2

<div ng-controller="someController">
    <my-directive>
      <input ng-model ="user.name">
      {{ user.name}}
    </my-directive>
    <my-directive>
      <input ng-model ="user.name">
      {{ user.name}}
    </my-directive>
</div>

user.name . ,

, user.name,

+1

"", AngularJS , .

"false" ( ), .

: {}, .

.

+1
source

Source: https://habr.com/ru/post/1612756/


All Articles