Skip to content

Instantly share code, notes, and snippets.

@pengux
Created December 29, 2013 13:47
Show Gist options
  • Select an option

  • Save pengux/8170644 to your computer and use it in GitHub Desktop.

Select an option

Save pengux/8170644 to your computer and use it in GitHub Desktop.
Angularjs confirm click directive
/*global window */
define(['angular', 'services'], function(angular, services) {
'use strict';
/* Directives */
angular.module('app.directives', [])
.directive('ngConfirmClick', [
function(){
return {
link: function ($scope, element, attr) {
var msg = attr.title || "Are you sure?";
var clickAction = attr.ngConfirmClick;
element.bind('click', function (event) {
if (window.confirm(msg)) {
$scope.$eval(clickAction);
}
});
}
};
}
]);
});
<a ng-confirm-click="delete('{{ object.id }}')" title="Do you really want to delete this object?">Delete</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment