AngularJS: How to pass arguments/functions to a directive?
Solution 1:
You can set two way data binding with property: '='
as Roy suggests. So if you want both key
and value
bound to the local scope you would do
scope: {
key: '=',
value: '='
},
Since you are passing these values, you have access to them in your directive's controller. But in case you want to run a function in the context of the parent scope, which seems to be what you want to do with the accept
attribute, then you would need to tell angular like this
scope: {
accept: "&"
}
Now, from your save
method you could call the function passed via accept
controller: function($scope, $element, $attrs, $location) {
$scope.save= function() {
$scope.accept()
};
}
Here's a jsfiddle
Solution 2:
scope: {
accept: "&"
}
Use lowercase letters for function names, otherwise it doesn't work.