This is a reduction of my directive:
app.directive('myDirective', function() { return { restrict: 'E', replace: true, template: '<form name="form" action="{{action}}" method="post" target="_blank">' + '<input type="hidden" name="item_name" value="{{itemname}}">' + '</form>', scope: { action: '@action', itemname: '@itemname', }, link: function(scope, element, attrs) { scope.action = attrs.action || 'http://www.example.com'; scope.itemname = attrs.itemname(); } }; }); and I use it this way:
<div ng-if="itemWasSelected"> <my-directive action="{{ 'http://www.example.com' }}" itemname="itemNameBuildFunction" /> </div> In my controller, I have:
$scope.itemNameBuildFunction = function() { return $scope.value1 + $scope.value2; }; I would expect my directive, when it is linked (it is inside an ng-if clause, so, I mean, when the ng-if condition evaluates to true), to call attrs.itemname() $scope function, to assign scope.itemname variable in the controller's link function.
Instead, what I get is the error:
TypeError: attrs.itemname is not a function Can you please give me some directions? As you can see, I'm quite confused, with angular directives... :-(
attrs.itemname()? never saw it defined... also if it was defined as a function attrs convert into JSON objects. so you would have to use angular.fromJson(attrs.itemname)itemname, which is not what I expect... :-(attrs.itemnamecontains a string (itemNameBuildFunction) which is a $scope function name...