As I understand, whenever we want to do DOM manipulations in Angular JS for whatever reasons (displaying data, controlling layout behavior, and so on) we should use directives. Now there are times that some DOM manipulation over one element needs info about other DOM elements to act.
One real world example: suppose we want to resize a div to always fit all the screen. So basically the div has one defined height and we want to change this height according to the content and so on to make the div fill the screen. Usually we need to consider other DOM elements like headers and so on when making this kind of manipulation.
Another example is the following: suppose we have a login form, and at the bottom of the form we want a link to allow the user to sign up if he doesn't have an account. When the user clicks the button it should flip the form from login to sign up (usually the other form is coded and hidden). That's fine, if we add a directive on the link to do this it needs to manipulate the form div, and if we put into the form div, it needs to communicate to the link.
In these cases (and I'm really being general, that those are just two possible situations), is there a general guideline on how should we act?
I mean, we have some DOM element <A>
and we want to manipulate it somehow, but to do so, we need information about another set of DOM elements <A1>
, ... , <An>
, so how do we deal with this with consistency?
I've thought on using require
and sharing the directive controller. But this is strange, taking again the resizing example we would have <div maintain-height>
being maintain-height
the directive with the logic to resize this div. Then to communicate with it we would need to put in every other place that triggers a resizing some directive requiring this one. It doesn't seem natural, and in other cases I thought it feels the same.
So, when we have this kind of situation, how can we deal with it maintaing everything well written, maintainable, testable, and etc?