Query params
Query params are the most usual to work with within web development, they follow this pattern:
/app?param1=hello¶m2=hi
You can get them via an observable, within the ActivatedRoute
, using the queryParams
method.
success: string;
constructor(private route: ActivatedRoute) {
this.route.queryParams.subscribe(params => {
this.success = params["success"];
});
}
Path variables
Path variables are those that you create within your Angular application.
/user/:id
These can simply be accessed using the route’s snapshot
method.
id: string;
constructor(private route: ActivatedRoute) {
this.id = this.route.snapshot.params.id;
}