I have been wondering why I have to use double brackets ()() when passing a method from an outer scope to a directive with an isolated scope using '&'.
It seems like the function is returned with callThat() and then I need to call it with another ().
The first function looks something like this:
function (b){return t(a,b)}
Here is some HTML:
<div class="jumbotron">
<div class="row" ng-controller='myController'>
<my-directive call-that="myPassedMethod"></my-directive>
</div>
</div>
This is my controller:
app.controller('myController', function($scope){
$scope.myPassedMethod = function(){
console.log('War, war never changes');
}
});
And here is my directive:
app.directive('myDirective', function() {
return {
restrict: 'E',
scope: {
callThat : '&'
},
templateUrl: 'something_irrelevant.html',
controller: function ($scope) {
$scope.calledFromIrrelevantTemplate = function () {
$scope.callThat()(); // why do I need to use ()(); here?
};
}
}
});
Can anyone explain this concept to me? (I'm not an experienced JS developer, so please use simple language).