Call controller from directive using without isolated scope using scope.$apply
http://angularjs.org/
by greatCar
HTML
<!-- https://stackoverflow.com/questions/17583004/call-a-controller-function-from-a-directive-without-isolated-scope-in-angularjs -->
<div ng-controller="MyCtrl">
<button confirm="Are you sure?" confirm-action="doIt()">Do It</button>
</div>
JavaScript
var app = angular.module('myApp', []);
app.directive('confirm', function ($parse) {
return {
restrict: 'A',
scope: true,
link: function (scope, element, attrs) {
element.bind('click', function (e) {
scope.$apply(attrs.confirmAction);
});
}
};
});
function MyCtrl($scope) {
$scope.doIt = function () {
alert('hi')
};
}