how do i bind a directive to an injected service instead of a parent or
isolated scope?
related to this question: How do I create a dynamic nav which gets allowed
menu items passed to it?
Basically, I have a nav outside of any views. The nav needs to display
menu items which a user has access to.
I create the nav markup with a directive like so:
<tree family="treeFamily"></tree>
Where treeFamily is the data which will be used to build the navigation menu.
However, since my nav is outside of any views, it doesn't have a
controller, so there is no scope variable called treeFamily. Which means
the directive doesn't get any data to create a navigation.
I originally thought I could just inject a service with the data for the
menu items, but then there is no way that I can see to tell an angular
directive to use data taken from an injected service for binding.
The only other way that seems to be possible is to have a $rootScope
variable called treeFamily and have the directive generated markup bind to
that instead.
No comments:
Post a Comment