I am trying to setup a confirmation dialog on an ng-click
using a custom angularjs directive:
app.directive('ngConfirmClick', [
function(){
return {
priority: 1,
terminal: true,
link: function (scope, element, attr) {
var msg = attr.ngConfirmClick || "Are you sure?";
var clickAction = attr.ngClick;
element.bind('click',function (event) {
if ( window.confirm(msg) ) {
scope.$eval(clickAction)
}
});
}
};
}])
This works great but unfortunately, expressions inside the tag using my directive are not evaluated:
<button ng-click="sayHi()" ng-confirm-click="Would you like to say hi?">Say hi to {{ name }}</button>
(name is not evaluated is this case). It seems to be due to the terminal parameter of my directive. Do you have any ideas of workaround?
To test my code: http://plnkr.co/edit/EHmRpfwsgSfEFVMgRLgj?p=preview
For me, https://www.w3schools.com/js/js_popup.asp, the default confirmation dialog box of the browser worked a great deal. just tried out this:
Simple.. :)
But I think you can't customize it. It will appear with "Cancel" or "Ok" button.
EDIT:
In case you are using ionic framework, you need to use the ionicPopup dialog as in:
For more details, refer: $ionicPopup
Its so simple using core javascript + angular js:
If you click OK, then delete operation will take, otherwise not. * id is the parameter, record that you want to delete.
You don't want to use
terminal: false
since that's what's blocking the processing of inside the button. Instead, in yourlink
clear theattr.ngClick
to prevent the default behavior.http://plnkr.co/edit/EySy8wpeQ02UHGPBAIvg?p=preview
In today's date this solution works for me:
Credits:https://gist.github.com/asafge/7430497#file-ng-really-js
I wish AngularJS had a built in confirmation dialog. Often, it is nicer to have a customized dialog than using the built in browser one.
I briefly used the twitter bootstrap until it was discontinued with version 6. I looked around for alternatives, but the ones I found were complicated. I decided to try the JQuery UI one.
Here is my sample that I call when I am about to remove something from ng-grid;
I hope this helps someone. I was pulling my hair out when I needed to upgrade ui-bootstrap-tpls.js but it broke my existing dialog. I came into work this morning, tried a few things and then realized I was over complicating.
Confirmation dialog can implemented using AngularJS Material:
Implementation example: Angular Material - Dialogs