I have a service where I read couple of parameters from the URL. looks good till I try to inject the service in the constructor
of the app.component.ts
or I try to call a service method from the app.component.ts
. Then the url-parameters are undefined.
Any idea what could be the reason for that?
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) {
...
}