Skip to content

Instantly share code, notes, and snippets.

@michaelhenrique182
Created January 2, 2018 12:03
Show Gist options
  • Save michaelhenrique182/be1134f211ba4a67d3203b12c5d2a9cd to your computer and use it in GitHub Desktop.
Save michaelhenrique182/be1134f211ba4a67d3203b12c5d2a9cd to your computer and use it in GitHub Desktop.
[Angular] Router Query Params
-- no template
<a [routerLink]="['users']" [queryParams]="{ page: 87 }">Ir para página 87 de usuários</a>
-- no componente (ou serviço)
goTo(page: number) {
this.router.navigate(['/users'], { queryParams: { page: page } });
}
-- consumindo query params no componente destino UsersComponent
export default class UsersComponent {
constructor(
private route: ActivatedRoute,
private router: Router) {}
ngOnInit() {
this.sub = this.route
.queryParams
.subscribe(params => {
this.page = +params['page'] || 0; // page
});
}
ngOnDestroy() {
this.sub.unsubscribe();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment