从内部指令传递参数给ngChange事件调用 [英] Passing arguments to ngChange event call from inside directive
问题描述
我有一个接受 NG-变化
属性的指令:
I have a directive that accepts an ng-change
attribute:
<radio-buttons options="optionsList"
ng-model="myModel"
ng-change="myCallback($event)"></radio-buttons>
我在我的控制器中定义的函数, myCallBack函数
,看起来像这样:
$scope.myCallback = function(e) {
console.log("Callback from controller");
console.log(e);
}
下面的功能选择我的单选
指令中存在。我需要定义时,在选择功能我里面的指令执行的ngChange回调:
The following function select exists within my radioButton
directive. I need to define when the ngChange callback is executed inside my directive in the select function:
function select(scope, val) {
if (!scope.disabled && scope.selectedValue != val) {
scope.selectedValue = val;
scope.model = val;
scope.callback.call();
}
}
我遇到的问题是参数在
<我的指令的 myCallBack函数
不是相处当我执行通过$事件选择
函数内部code> myCallBack函数。
The problem I am having is the argument $event
in myCallback
is not getting passed along when I execute myCallback
inside the select
function of my directive.
小提琴: http://jsfiddle.net/dkrotts/BtrZH/7/ 已更新的http://jsfiddle.net/dkrotts/BtrZH/8/
我在做什么错了?
推荐答案
您必须通过参数,像这样的回调:
You have to pass the parameter in the callback like so:
callback({parametername: value});
和你不得不与一个在声明的参数名匹配的 HTML
And you have to match the parameter name with the one declared in the HTML
在您的情况:
callback({$event: val})
这篇关于从内部指令传递参数给ngChange事件调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!