-
-
Notifications
You must be signed in to change notification settings - Fork 0
Get Query String from Route URI
Tyler Ruff edited this page Jun 14, 2022
·
1 revision
Getting a query string from a route URI element is simple (ex: example.com/home?id=7)
- Import ActivatedRoute (in component.ts):
import { ActivatedRoute } from '@angular/router';
- Add to component class:
...
id: string | undefined;
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.route.queryParams
.subscribe(params => {
this.id = params['id'];
}
);
...
- The query string will now be available to the component as the "id" variable:
<ng-container *ngIf="id">
...
<app-item [itemId]="id"></app-item>
<span>
{{ id }}
</span>
...
</ng-container>
Join the Blazed Development Group today to get involved in open source collaborative projects.
Discover our FREE learning resources, the Blazed University, Web Development School, and Blazed City.