angular routing query params code example
Example 1: angular router with wuery param
goProducts() {
this.router.navigate(['/products'], { queryParams: { order: 'popular' } });
}
http://localhost:4200/products?order=popular
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.route.queryParams
.filter(params => params.order)
.subscribe(params => {
console.log(params);
this.order = params.order;
console.log(this.order);
}
);
}
Example 2: get route query params angular
export class HeroComponent implements OnInit {
constructor(private _activatedRoute: ActivatedRoute, private _router:Router) {
_router.routerState.queryParams.subscribe(
params => console.log('queryParams', params['st']));
Example 3: this.router.navigate
<a routerLink="/red-pill/neo">Go!</a>