From the Angular docs:
& or &attr - provides a way to execute an expression in the context of the parent scope. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given and widget definition of scope: { localFn:'&myAttr' }, then isolate scope property localFn will point to a function wrapper for the count = count + value expression.
This gives me the impression that something like this should be possible, but it isn't working. What am I doing wrong?
myApp.directive('test', function () {
return {
restrict: 'E',
replace: true,
template: '<div><input type="button" ng-click="thefunc()" value="{{title}}"/></div>',
scope: {
title: '@',
thefunc: '&'
}
};});
HTML:
<test thefunc="alert('Here you go.')" title="Click me for a popup"/>
Angular is looking for an "alert" on the controller's scope -
$scope.alert = function(){..}
and not the window.alert
Here is an updated version: