Angular directive injection

Why is the controller introduced in the directive executed through require, but in other dependencies through the annotation of the array?

+4
source share
2 answers

Require controller

If you want to share the same controller instance, use require.

requires the provision of another directive, and then includes its controller as a parameter of the communication function. Therefore, if you have two directives for one element, your directive may require another directive and access its management methods. For this, ngModel is usually used.

^require, with the addition of a carriage, checks the elements above the directive in addition to the current element, in order to try to find another directive. This allows you to create complex components where the "subcomponents" can interact perfectly with the parent component through their controller. Examples may include tabs where each panel may link to common tabs to handle switching; an accordion set can ensure that only one is open at a time; and etc.

, . require - .

angularjs

angular DI ?

+4

- . require, . " " , "".

, , -, , : " , ... , , ".

+1

All Articles