how can I pass function to angularjs directive and execute it with parameters from the directive?
I am trying to render my directive with this "test-directive(cb="getDetails()") and it doesn't work
Say a directive is like this
angular.module('app', []).directive('testDirective', function () {
return {
restrict: 'E',
scope: {
callback: '&'
}
};
});
Then in html where you integrate the directive set the callback to a function which will be defined on your controller.
<test-directive callback="getDetails(newValue, oldValue)"/>
And in controller define getDetails
$scope.getDetails = function (newValue, oldValue) {
// do whatever you want here
}
While you invoke your callback from directive then you have to call it like
$scope.callback({
newValue: <a value>,
oldValue: <another value>
});