I am attempting to create a slider using angularJS. Within this slider, I have implemented a child directive with event listeners. Whenever the main event (mousedown) is triggered, it invokes a function from the parent directive through a controller and updates the styles of multiple HTML elements. This setup works perfectly when there is only a single directive on the page. However, if there are multiple directives present, it seems like every parent controller gets invoked simultaneously. I am puzzled by this behavior.
Plknr: http://plnkr.co/edit/9vGXxjDbqqEOzLcXRkoW?p=preview
Parent directive:
return {
restrict: 'EA',
scope: {
sliderStep: '@',
sliderBothHandles: '@',
sliderMinVal: '=', //value min handle
sliderMaxVal: '=', //value max handle
sliderMin: '@', //minimum value authorized
sliderMax: '@' //maximum value authorized
},
templateUrl: 'slider_template',
controller: sliderController,
transclude: true
};
Child directive:
return {
restrict: 'EA',
link: link,
require: '^mcsSlider',
scope: true
};
Markup:
<mcs-slider slider-step="1" slider-max-val="formCtrl.value1" slider-min="0" slider-max="7200">
<div mcs-slider-handle class="slider-handle max-slider-handle round" aria-valuemin="0" aria-valuemax="7200" aria-valuenow="{{formCtrl.value1}}" tabindex="0" style="left:0%;"></div>
</mcs-slider>