Let's define a trivial scenario where a blog has a list of Post
s, each with Comment
s and other Object
s.
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.
Comment
s are loaded when Post
is first loaded, in the link
method of the directive associated to <comments>
. How can i trigger Comment
s reloading when (the parent) Post
changes?
- In the directive associated to
<comments>
, should I place ascope.$watch('post')
to listen when the associatedPost
changes and trigger on change theComment
s reloading? - Should I create a
register
function in thePost
directive, whereComment
s andObject
s subscribe their own controllers, and are notified from aPost
function when they need to be reloaded? That is, a manually implemented Observer pattern. $broadcast
and$on
? Not sure how to implement them with isolated scopes.