When working with a service that reads parameters from the URL, everything seems to be functioning properly until attempting to inject the service into the constructor of the app.component.ts file or trying to call a service method from the app.component.ts. At this point, the URL parameters appear as undefined.
Does anyone have any insight into what might be causing this issue?
my-service.service.ts
:
...
public param1;
constructor(public router: Router, private http: HttpClient) {
this.param1 =
this.router.parseUrl(this.router.url).queryParams['todo'];
console.log('param1: ' + this.param1); // returns undefined if the service is injected in app.component
}
....
app.component.ts
:
...
import { MyService } from './service/my-service.service';
....
constructor(private http: HttpClient, public myService: MyService) {
...
}