Validate modal with ngDialog

I am using ngDialog in my application, and I would like to create a general confirmation modal code that I can use when I need, the confirmation message will be different.

My questions:

1- Does the directive with ngDialog functionality make a good idea and what is its design?

2- what is the difference between confirm () and openConfirm () in ngDialog code.

Thanks in advance

+7
angularjs ng-dialog
source share
1 answer

Good to answer your questions,

1 - You can create a directive for it that has scope , say type , to which you pass the type of confirmation (i.e. submit to confirm the confirmation, delete to confirm the deletion), and the directive should display a message based on the type you specified.

2 - openConfirm() is a type of ngDialog that can only be closed by confirmation of the action (unlike ngDialog.open() ), so you cannot close the dialog by clicking anywhere in the DOM . confirm() is just the method you use to close the dialog, you use this method to close the dialog and resolve the promise that was returned when the modal file was opened, so it can go <button ng-click="confirm()">Confirm</button> inside your dialog.

Hope this helped you

Update

openConfirm() Opens a dialog box that by default does not close when you hit or click outside the dialog box. The function returns a promise that is either allowed or rejected, depending on how the dialog was closed.

To break a promise, your dialogue should look something like this:

With ngDialog controller

 ngDialog.openConfirm({ template: '<div></div>', controller: ['$scope', function($scope) { // Controller logic here }] }).then(function (success) { // Success logic here }, function (error) { // Error logic here }); 

With directory controller

 ngDialog.openConfirm({ template: '<div></div>', scope: $scope, // <- ability to use the scopes from directive controller }).then(function (success) { // Success logic here }, function (error) { // Error logic here }); 

You can use your directory controller while you go through scope: $scope inside the dialog box

Here is a daemon showing you how you can use a type

Try switching the type in index.html from confirm to remove and see the updated content and button text in the dialog

+18
source share

All Articles