I want to call a function defined in a directive, just the opposite of this stackoverflow question
I tried this but does not work.
app.directive('myDirective', function() {
return {
link: function(scope, element, attrs) {
scope.someDirectiveFn = function(arg) {
return "in directive";
};
},
}
});
function MyCtrl($scope) {
alert($scope.someDirectiveFn());
}
Is that possible? how could I get it? is it a bad practice?
EDIT
I got this way:
.controller('MyCtrl', function($scope) {
alert($scope.func());
})
.directive('myDirective', function() {
return {
controller: function($scope, $element){
$scope.func = function() {
return "text";
};
}
}
});