70
rated 0 times
[
71]
[
1]
/ answers: 1 / hits: 35506
/ 9 Years ago, wed, july 15, 2015, 12:00:00
I'm trying to pass a callback function from a controller to a directive.
Here's the callback function code:
$scope.onImageSelect = function(image) {
alert('SET');
$scope.card.image = image;
};
Directive usage:
<google-image-search callback=onImageSelect />
Directive code:
ngmod.directive('directive', function() {
return {
templateUrl: '/templates/template.html',
scope: {
callback: '&'
}
}
});
Callback usage in template:
<a data-ng-click=callback(url)></a>
However, this gives me the following error:
TypeError: Cannot use 'in' operator to search for 'onImageSelect'
I've seen a lot of similar questions, but could not understand where am I wrong.
More From » angularjs