How to call angular function when click p-dialog close(X) button?

。_饼干妹妹 提交于 2019-12-10 21:16:09

问题


How to call angular function when click p-dialog close(X) button?

I have searched and just tried this (onHide)="cancel()" . But it's not working. Kindly share your solutions.

I know we can use a close/cancel button to hide the popup. But in my scenario I want to call an event when clicking the (X) button click.


回答1:


Actually (onHide)="cancel()" works fine according to this Plunkr.




回答2:


Try: (click)="cancel()" instead.

I had the same error but I solved it by using the click method. Grettings :)




回答3:


You should to use two events follow:

onBeforeHide: EventEmitter<any>;
onAfterHide: EventEmitter<any>;

use in html as

(onBeforeHide)="onBeforeHide()"
(onAfterHide)="onAfterHide()"

Refer: https://github.com/primefaces/primeng/issues/956




回答4:


A workaround is to use a boolean to display the p-dialog with

   [(visible)]="myBoolean"

You set that boolean to true when you want to display the p-dialog Then use the (click) event. For instance

    (click)="doSomething($event)".

In your ts do

    doSomething(event) {
        // If we are clicking the close button and not something else
        if (event.target.className === "fa fa-fw fa-close") {
            myBoolean = false;
        }
    }


来源:https://stackoverflow.com/questions/43848250/how-to-call-angular-function-when-click-p-dialog-closex-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!