get params from route angular 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: angular get url params
import { ActivatedRoute } from "@angular/router";
private $route: ActivatedRoute
this.$route.params.forEach(param =>
this.myvar = param['whatever your param name is']
);
Example 3: this.router.navigate
<a [routerLink]="['/', 'red-pill', {x: 'white-rabbit'}, 'neo']">
Param!
</a>