shlomiassaf / ngx-modialog

Modal / Dialog for Angular
http://shlomiassaf.github.io/ngx-modialog
MIT License
686 stars 242 forks source link

Wrong delay when closing custom modal and question about default params #195

Closed basters closed 8 years ago

basters commented 8 years ago

Hello everyone, I have two questions about working with CustomModal.

1) The main question about wrong delay when I exec this.dialog.close(). I have found that it occurs in the OverlayComponent at the method canDestroy link

As we can see that method has a setTimeout for animation, but how I can disable animation? or why I don't have animation? I just have a delay for 1 second and after that dialog closes instantly. I wrote the same code of CustomComponent with your demo, but it works wrong with magic delay. My Custom Modal Component

2) And the second question - How I can set modal options for custom modal? For example I want to close modal by clicking outside of the modal window or by pressing esc button. How I can control this options when I use custom modals?

I have latest version of angular2-modal component (2.0.0-beta.13) and angular(2.0.0). The same problem was on angular RC5...

shlomiassaf commented 8 years ago

@wis-ekubesh (1) This delay is for protecting from cases where beforeDestroy handlers are not resolving. Yes, it's mainly for animation.

Animation's are added by plugins, bootstrap or vex, they both have animations. Each plugin is responsible for adding the beforeDestroy handlers according to needs. You can create you'r own plugin where you control what to register in beforeDestroy. I agree that this timeout is not ideal but for now it's what I came up with as this is just a protection layer and it should not fire. Bootstrap plugin expects the bootstrap CSS, VEX plugins expects the vex css, they both have the animation classes.

For (2) The OverlayConfig supplied to a modal.open() function is where you define these values. OverlayConfig.context holds the context for a modal instance. The base class for OverlayConfig.context is OverlayContext which has the base properties every overlay should have:

export class OverlayContext {
  inElement: boolean;
  isBlocking: boolean;
  keyboard: Array<number> | number;
}

So, let's assume you are using the bootstrap plugin:

const builder = new BSModalContextBuilder<any>();

builder.isBlocking(false);
builder.keyboard([27]);

// and some bootstrap specific options:
builder.size('lg');

let overlayConfig: OverlayConfig = {
  context: builder.toJSON()
};

this.modal.open(CustomModal, overlayConfig);
shlomiassaf commented 8 years ago

I'll close this stale issue, please re-open with a comment if it still an issue.