Attaching click to anchor tag in angular
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:
- Remove the
href
tag from<a>
to prevent a page forwarding. - Then just add your usual Angular click attribute and function.
- Add to
style: "cursor: pointer"
to make it act like a button