How can a directive call a function from a controller with some parameters ?
I would to give the variable myVar to the scope.$apply(attrs.whattodo);
HTML :
<div ng-app=component>
<div ng-controller=ctrl>
<span ng-repeat=i in myarray>
<span customattr whattodo=addVal>{{i}}</span>
</span>
</div>
Controller JS :
function ctrl($scope) {
$scope.myarray = [1];
$scope.addVal = function (value) {
$scope.myarray.push(value);
}
}
Directive JS :
angular.module('component', []).directive('customattr', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var myVar = 5;
scope.$apply(attrs.whattodo);
}
};
});