Angular Directives Exposing State
It’s quite easy to find advice on Directives Talking to
Controllers (tell the directive what
function to call) and Directive to Directive
Communication (one requires a
controller defined in the other)*. Controller to Controller
communication is usually via
Services.
Many directives expose state via the scope to elements defined further down the
tree (e.g. ng-repeat
).
But I’ve yet to see any advice on exposing state from a directive to the rest
of the world.
The approach I took in angular-virtual-scroll
was to use the ng-model
attribute (if present) to point to a model that will hold all important state variables. See here if you’re interested. I made the dangerous assumption that nobody would try to alter the state - surely they wouldn’t.
* Pretty much everything at http://www.egghead.io/ is golden.