UNPKG

760 BJavaScriptView Raw
1angular.module('confirm-click', [])
2 .directive('confirmClick', ['$window', '$q', function ($window, $q) {
3 return {
4 restrict: 'A',
5 link: function (scope, element, attr) {
6 console.log('linking ConfirmClick');
7 var question = attr.confirmClick || 'Are you sure?';
8 var ask = $window[attr.confirmFn] || confirm;
9
10 element.on('click', function (event) {
11 console.log('click on element');
12 var answer = ask(question);
13 if (!answer) {
14 event.preventDefault();
15 }
16 });
17 }
18 };
19 }]);
20
21angular.module('ClickApp', ['confirm-click'])
22 .controller('ClickController', function ($scope) {
23 $scope.popAlert = function () {
24 alert('pop alert!');
25 };
26 });