I am having an issue on an Angular2 application I have built where when I fire a click event from the view the page jumps to the top of the DOM. I have tried to use the 'preventDefault()' binding to the event method to stop this from happening but this does not solve my issue. Can anyone advise me as to thy this is happening?
Here is my code.The view:
<div class='pagination-wrapper'>
<a class='page-link prev' [ngClass]="{'disabled': activePage <= 0}" (click)=pageBackward($event)>prev</a>
<a *ngFor='let pageLink of pages' class='page-link' [ngClass]="{'selected': activePage === pageLink}" (click)=jumpToPage(pageLink)>{{ pageLink + 1 }}</a>
<a class='page-link next' [ngClass]="{'disabled': activePage + 1 >= pages.length}" (click)=pageForward($event)>next</a>
</div>
And the relevant component code:
pageForward($event) {
$event.preventDefault();
this.activePage++;
this.paginationChange.emit(this.activePage);
}
pageBackward($event) {
$event.preventDefault();
this.activePage--;
this.paginationChange.emit(this.activePage);
}
jumpToPage(pageNum) {
this.activePage = pageNum;
this.paginationChange.emit(pageNum);
}
Thanks!