There are three different options in directive "=", "&", "@"
The two you are wanting to use are
"&" will let you pass in a function
"@" will accept a string
Something worth nothing, camelCase properties will be automagically parsed by angular and turned into camel-case (notice the hypen) when assigning a value
.directive("myDialog", function() {
return {
restrict: "E", // allows us to restrict it to just elements ie <my-dialog>
scope: {
"close": "&onClose", // putting a new name here allows us to reference it different on the html
// would become <my-dialog on-close="someFn()"></my-dialog>
"myParam": "@"
},
template: "<button type='button' data-ng-click='close()'>Dummy - {{myParam}}</button>"
};
});
.controller("fooCtrl", [function(){
var vm = this;
vm.someRandomFunction = function(){
alert("yay!");
};
}]);
The final html would look like
<div ng-controller="fooCtrl as vm">
<my-dialog on-close="vm.someRandomFunction()" my-param="55"></my-dialog>
</div>
Worth
reading as well as the links on the answer
Plnkr