In my directive (parent-directive
), I have a slider called mySlider
. When the slider is stopped, it triggers an event that calls an Angular $resource
service with two parameters. The service then returns an object.
The structure of the directives is as follows:
<parent-directive>
<div ui-slider="slider.options" ng-model="mySlider" id="my-slider">
<span child-directive-one></span>
<span child-directive-two></span>
<span child-directive-three></span>
<div>
<span child-directive-four></child-directive-four>
</div>
</parent-directive
When the user drags the slider, the service is called with different parameters to retrieve a new result. Based on this result, I need to update the child directives.
I am considering three ways to achieve this:
- Using
ng-model
for all child elements instead of directives and binding them to the scope of a controller within theparent-directive
. - The second option involves creating a controller within the
parent-directive
to send and receive data from the service and share it with thechild-directives
for updating purposes. - The last approach is to create a state variable in the service and update it using a controller similar to the first option mentioned above. Then, use
$watch
to monitor changes in the variable's state and update thechild-directives
accordingly.
What would be the best way to proceed?
You can take a look at a sample code here: http://jsfiddle.net/v5xL0dg9/2/
Thank you!