[英]child directive access every parent directive
I am trying to do a slider
in angularJS. 我正在尝试在angularJS中做一个
slider
。 I have a child directive with events listeners. 我有一个带有事件侦听器的子指令。 When the main event (
mousedown
) is listened to, it calls a function from the parent directive (via a controller) and changes style of various html elements. 当侦听主事件(
mousedown
)时,它将从父指令(通过控制器)调用一个函数,并更改各种html元素的样式。 Works like a charm when there is only one directive on the page. 当页面上只有一个指令时,它就像一个超级按钮。 If there are more than one, every parent controller is called.
如果有多个,则调用每个父控制器。 I don't understand why.
我不明白为什么。
Plknr: http://plnkr.co/edit/9vGXxjDbqqEOzLcXRkoW?p=preview 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>
The problem seems to be inside the directive mcsSliderHandle
, in the $interval
function. 问题似乎在
$interval
函数的mcsSliderHandle
指令内部。 You're using $('.min-slider-handle')
that will find all the elements with that class! 您正在使用
$('.min-slider-handle')
来查找该类的所有元素! You have to retrieve only the elements inside the current directive. 您只需要检索当前指令内的元素。 Wrong but working plunker here
错了,但是在这里打工
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.