how to call function in $scope inside directive
http://angularjs.org/
by manoj
HTML
<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')
};
}