简体   繁体   中英

primeng p-dialog change URL on close button - angular 2

As per primeng close button html, href is pointing to #

<a *ngIf="closable" [ngClass]="{'ui-dialog-titlebar-icon ui-dialog-titlebar-close ui-corner-all':true}" href="#" role="button" (click)="close($event)" (mousedown)="onCloseMouseDown($event)">
                    <span class="fa fa-fw fa-close"></span>
</a>

My Piece of code is :

<p-dialog header="Student Confirmation" modal="true" appendTo="body" [resizable]="false">

How can we change default href from "#" to something else in angular?

Tried below solution, but doesn't work for me :

 public close(): void {
        this.router.navigateByUrl("../studentAssignments", { relativeTo: this.route });
        super.close();
    }

I don't think this can be possible because this the default HTML of primeng's component.

What you can do in this case is you can call onHide function on dialog component and redirect to wherever you want like this

<p-dialog (onHide)="close()" header="Student Confirmation" modal="true" appendTo="body" [resizable]="false">

public close(): void {
        this.router.navigateByUrl("../studentAssignments", { relativeTo: this.route });
    }

Working Example

Remove href="#" from the code

OR

Add href="javascript:void(0)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM