I'm using the ActivatedRoute to get a parameter from my route in an injected service. If I specify the service as a provider in the app module or app component the param map is empty when it gets called. If I specify it as a provider in the component that pulls in the service it has the parameter.
Why is this working this way. I've had trouble finding good information on how the ActivatedRoute is scoped and how it interacts with services.
Link to this behavior in plnkr. Uncomment line 11 (providers field) in a.component.ts to see it working when you click me! https://plnkr.co/edit/3U9dZm9fdUlG6KW3GyoQ
import {Component, OnInit} from '@angular/core'
import {AService} from './a.service.ts'
@Component({
selector: 'app-a',
template: `
<div>
<h2>Hello {{id}}</h2>
</div>
`,
// providers: [AService]
})
export class AComponent implements OnInit {
id: string;
constructor(private aService: AService) {
}
ngOnInit() {
this.id = this.aService.getId();
}
}