Let's define a trivial scenario where a blog has a list of Posts, each with Comments and other Objects.
In structuring the Post page, I can image defining the following elements:
<post post="post"></post>
<comments post="post"></comments>
<objects post="post"></objects>
or:
<post post="post">
<comments></comments>
<objects></objects>
</post>
To provide reusability, each directive associated to an element has its own isolated scope.
Considering then for example the directive associated to <comments>, I can supply it with an Add button, a Reload comments button etc. That's easy, as long as its functions are limited to its own scope.
Comments are loaded when Post is first loaded, in the link method of the directive associated to <comments>. How can i trigger Comments reloading when (the parent) Post changes?
- In the directive associated to
<comments>, should I place ascope.$watch('post')to listen when the associatedPostchanges and trigger on change theComments reloading? - Should I create a
registerfunction in thePostdirective, whereComments andObjects subscribe their own controllers, and are notified from aPostfunction when they need to be reloaded? That is, a manually implemented Observer pattern. $broadcastand$on? Not sure how to implement them with isolated scopes.