I have an AngularJS directive with function parameter, and it works perfectly when I call the directive simply it works, and I want to generalize it. What I got so far:
.directive('panelBox', function () {
return {
restrict: 'E',
scope: {
values: '=',
calculatefn: '&'
},
templateUrl: '/ProfitCalculator/PanelBox',
controller: function ($scope) {
$scope.calculate=function() {
$scope.calculatefn();
}
}
}
})
in the main scope:
$scope.smartBookValues= {
name:'Smart Book',
text:'Smart book header',
controls:[]
};
and the html:
<panel-box values="smartBookValues" calculateFn="smartBookCalculateFn()"></panel-box>
now I'm trying to bind the values and calculateFn, so I started with calculateFn and did:
$scope.smartBookValues= {
name:'Smart Book',
text:'Smart book header',
controls:[],
calculateFn:'smartBookCalculateFn()'
};
and the html:
<panel-box values="smartBookValues" calculateFn="{{smartBookValues.calculateFn}}"></panel-box>
but i get: [$parse:syntax]
Syntax Error: Token '{' invalid key at column 2 of the expression [{{smartBookValues.calculateFn}}] starting at [{smartBookValues.calculateFn}}].