Jesse
Jesse

Reputation: 1723

A directive can require a controller on it's parent(s)?

From the angular docs it describes the way to specify where to look for a controller from a directive using the require property.

^^ - Locate the required controller by searching the element's parents. Throw an error if not found.

What would be a case where an element has two or more "parents".. A DOM element can only have one parent so what do the docs refer to?

Upvotes: 0

Views: 57

Answers (1)

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

^^ - Locate the required controller by searching the element's parents. Throw an error if not found.

The doc is saying that controller will be searched over the element's parent divs but not current element and if there's no such controller in parent div then it will throw an error.

--grand parent div
  --parent div
    --directive element

In above tree structure from the directive element it will search the controller not itself in directive element but to parents meaning that first search in parent div if found use that controller and if not, search again to its parent that is grand parent div, so now if the controller is found then use that and this searches until parent divs end and even if such controller not found then only it throws an error.

Hope, You understood!

Upvotes: 1

Related Questions