In a directive, where you set a method callback through an arg, say:
<my-directive callback='showAlert()' />
You can retrieve the variable through the scope setting in the return:
scope: {
callback: "&callback"
}
If the callback is not set, eg:
<my-directive />
The value of $scope.callback is still:
$scope.callback():function (locals) {
return parentGet(scope, locals);
}
Is there a good way to check that the callback was not set?
One way i can think off is to check the attribute parameter for the directive name like
link: function (scope, elm, attrs) {
if(attrs.callback) {
//this attribute has been defined.
}
}
You can use &?
insteand of &
. It will make $scope.callback equal to undefined
if it is not provided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With