I'm new in Angular and I have problem with pass params from url to view on first load.
In my URL i have parameter page:
.../catalog?page=3
In component I have next code:
export class CatalogListComponent implements OnInit {
page;
constructor(private route: ActivatedRoute){
}
ngOnInit(){
this.route.queryParams.subscribe(params => {
this.page = +params['page'] || 1;
});
}
setPage(page: number) {
this.router.navigate(['catalog'], { queryParams: {...this.queryParams, page } });
}
}
In view I use ngb-pagination:
<ngb-pagination class="pagination"
[collectionSize]="items.total"
[rotate]="true"
[(page)]="page"
[maxSize]="5"
[pageSize]="20"
(pageChange)="setPage(page)"
>
</ngb-pagination>
When I'm open/refresh link in browser .../catalog?page=3 ngb-pagination always shows me page 1 instead of 3, but next navigation works fine([page num in url and in pagination the same).
What I'm doing wrong ?