Hi I am new to Angular and trying out the directives. Following is the code
HTML
<div ng-app="scopetest" ng-controller="controller">
<div phone action="callhome()"> </div>
</div>
javascript
angular.module("scopetest", [])
.controller("controller", function($scope){
$scope.callhome = function(){
alert("called");
}
})
.directive("phone", function(){
return {
scope: {
action:"&"
},
template: "<button ng-click='action()' >Call</button>"
};
});
My question is if we are passing the callhome function to the action attribute, and on ng-click we are calling the action function with parenthesis, then why do we need to specify the parenthesis while setting the attribute on phone directive ng-click='action()'? Why doesn't just ng-click='action' work? We are already specifying action="callhome()". Why needed at both places?