I've been struggling with subscribing to query string parameters in Angular 2+. Despite looking at various examples, I can't seem to make it work.
For instance, on this Stack Overflow thread, the question is about obtaining query parameters from a URL in Angular 2+.
Below is the code I have:
import { ActivatedRoute, Router } from '@angular/router';
...
export class MyComponent implements OnInit,OnDestroy {
private a: boolean = true;
private b: boolean = true;
constructor(route: ActivatedRoute) {
...
ngOnInit(): void {
this.route.queryParams.subscribe((queryParams:any) => {
this.a = queryParams.a;
this.b = queryParams.b;
});
The issue I am facing is that 'this' does not seem to point to my component, and setting 'a' and 'b' values which should be used to trigger *ngIf statements does not work as expected.
What could be going wrong?