shlomiassaf / ngx-modialog

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

Dialog Close Listener/Event #304

Open shabbir-dhangot opened 7 years ago

shabbir-dhangot commented 7 years ago

Hi I wish to know about the feature of close dialog listener or event. How Can I come to know the custom-model is closed.

I am calling custom model like below. openCustom() { this.modal.open(AdditionCalculateWindow, new AdditionCalculateWindowData(2, 3)); }

Now I want to know when dialog gets close. Please let me know How can I do that. I need to reset some data.

alfupe commented 7 years ago

If you do something like that (commented on #247) you will always get a result of null. This is caused because you are not opening a confirm dialog. I am exactly in the same problem. I would like to get some result from a non confirm modal.

openCustom() { 
    const dialog = this.modal.open(AdditionCalculateWindow, new AdditionCalculateWindowData(2, 3)); 

    dialog.then(resultPromise => {
            return resultPromise.result
                .then(
                    result => console.log('result', result),
                    () => console.log('Rejected')
                );
        });
}        
shivanand23 commented 7 years ago

Hi.. Anybody has got any solution for this ? please help.

alfupe commented 7 years ago

@shivanand23 yes! please see a very easy solution here: #320

shivanand23 commented 7 years ago

@alfupe Thank you so much Alex. It works like a dream.

Also in case user clicks outside the modal or presses the escape key and exists the modal I used the beforeDismiss() override.

beforeDismiss(): boolean { this.dialog.close("result to pass"); return false; }

alfupe commented 7 years ago

@shivanand23 yeah! I'm glad to see that! ;-)

Maseeharazzack commented 6 years ago

this.dialog.close() This doesn't work for me