Hello, I'm currently a beginner in Angular and I am experimenting with directives. Here is the code snippet that I am using:
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>"
};
});
I have a question regarding the use of the callhome
function in the action
attribute. When we call the action
function with parentheses on ng-click
, why is it necessary to specify the parenthesis while setting the attribute on the phone directive as ng-click='action()'
? Why wouldn't ng-click='action'
suffice given that we have already specified action="callhome()"
? Do we really need to include the parenthesis at both places?