Reputation: 27
how can I use this.router.url to check if my my URL contain specific parameter such as id? In one instance i am using following if url has profile to change search icon. i want to same for user/videos/:id but only when the id param is present in url
if (this.url.includes("profile")) {
this.searchIcon = true;
}
Upvotes: 0
Views: 19
Reputation: 31125
For a quick fix you could use the paramMap
snapshot from ActivatedRoute
.
import { ActivatedRoute } from '@angular/router';
...
export class SomeComponent implements OnInit {
id: any;
constructor(private _activatedRoute: ActivatedRoute) { }
ngOnInit() {
this.id = this._activatedRoute.snapshot.paramMap.get('id');
if (!!this.id) {
// `id` defined
} else {
// `id` undefined
}
}
}
Upvotes: 1