[英]Pass additional parameters to a directive callback angular js
I use a datepicker which returns a selected date as a value to its callback the datepicker is a plugin. 我使用datepicker返回一个选定的日期作为其回调的值,datepicker是一个插件。
In my callback method selectedDate i need to pass in additional parameters such as the dateValue to this selectedDate method. 在我的回调方法selectedDate中,我需要将其他参数(例如dateValue)传递给此selectedDate方法。 How can i achieve this
我怎样才能做到这一点
<datepicker callback="selectedDate" ></datepicker>
$scope.selectedDate= function (dateValue) {
}
So what you need is to specify the kind of params that you are expecting back, http://plnkr.co/edit/0fqMLYlEeBwQylo2Va1B?p=preview 因此,您需要指定期望返回的参数类型, http://plnkr.co/edit/0fqMLYlEeBwQylo2Va1B?p = preview
You directive basically asks for the variables on execution, 您的指令基本上要求执行时提供变量,
<test-dir callback="callback(a, b , c)"></test-dir>
and while execution you pass these values back: 在执行时,您将这些值传回:
app.directive('testDir', function() {
return {
restrict: 'E',
scope: {
callback: '&'
},
template: '<div ng-click="testFunc()">click me</div>',
link: function(scope) {
scope.testFunc = function() {
scope.callback({a: 1, b : 2, c: 3});
}
}
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.