I have a controller and a directive. In the directive's communication function, I call the controller function. When calling the controller function, I want to access the controller volume inside the controller function. But I get $ scope as undefined. How to access the current area. Here is the fiddle http://jsfiddle.net/9t294ox6/1/
I can access the scope using "this", but $ scope is undefined. Why is this happening?
This is my directive.
app.directive('myDirective', function() {
return {
scope: { someCtrlFn: '&callbackFn' },
link: function(scope, element, attrs) {
scope.someCtrlFn({arg1: 22});
},
}
});
my controller
function MyCtrl($scope) {
$scope.ctrlFn = function(test) {
debugger
console.log(test);
}
}
My html
<div ng-controller="MyCtrl">
<div my-directive callback-fn="ctrlFn(arg1)"></div>
</div>
source
share