You can use routerLink
(which is an alternative of href
for angular 2+) with click event as below to prevent from page reloading
<a [routerLink]="" (click)="onGoToPage2()">Go to page</a>
I think you are not letting Angular work for you.
In angular 2:
href
tag from <a>
to prevent a page forwarding.style: "cursor: pointer"
to make it act like a buttonYou just need to add !!
before your click method handler call: (click)="!!onGoToPage2()"
. The !!
will prevent the default action from happening by converting the return of your method to a boolean. If it's a void
method, then this will become false
.
<a href="#" (click)="onGoToPage2()">Go to page 2</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With