An element does not receive a selection if the highest priority directive does not have one

Is it correct that angular does not create a selection region for an element that has two directives, where the highest priority directive does not have a selection region and the lower priority directive?

I have the following plunker that has 2 directives and a controller:

http://plnkr.co/edit/zEnMH6h0ILURHSgx0DLX?p=preview

If you open the console, you will see the logs of the scope of directives and the controller. The noIsoScope directive does not have a scope and has priority 1. The scope isoScope directive has a scope but the priority is 0. When I use each directive independently, everything works as excluded. When I use both of them together, the isoScope directive shows that it uses the controller scope (since it has the same $ id based on the logs) as its own.

Do I have to make sure that whenever I use multiple directives for an element, if one of them has a selection area, then it should have the highest priority?

+4
source share
1 answer

The short answer is yes .

It makes no sense to have two directives requiring both a highlight region and a parent region. The idea would be to think about how the directive can work with each other. How does the normative directive of the parent region work correctly if its scope is a selection?

I think the angular team decided not to give a warning in this situation (there may be a mistake).

  • if a selection area is required for a lower priority, which means that it has a strict requirement for data from the parent areas
  • If a higher priority does not require a region, which means that it inherits the parent region and potentially uses this data in the template.

This is a catch situation 22: It does not make sense that the non isolate directive uses the allocation region, as it may depend on the fact that it does not isolate. At the same time, the isolate directive most likely depends on its isolation.

From Igor Minar , he talks about several areas of isolation, but on the same issue basically:

My suggestion is to use selection areas when you create reusable components that are supported by the template. If you want to compose several directives, you must design them so that one directive is the main one (with the template), and the other directives are just auxiliary directives (like dashes or mixins in some programming languages).

+1
source

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


All Articles