Reputation: 219
I have a strange problem. I am working on a library that is imported into my project where I have a service specified as below:
import { Injectable } from '@angular/core';
import { Location } from '@angular/common';
@Injectable({
providedIn: 'platform'
})
export class MyService {}
However when I import this into my project, I get a NullInjector error for Location.
If I change the Injectable to providedIn: 'root', then I get a NullInjector for MyService.
Does anyone know how I can use providedIn: 'platform' and still be able to inject Location?
I've tried adding Location to the app module and it made no difference.
Upvotes: 0
Views: 232
Reputation: 219
The problem was that I was not properly importing MyService in the project that was receiving it. providedIn: 'platform' simply masked the wider issue.
Once I imported it in imports: [] I was able to revert all the providedIns back to 'root' and the problem is gone.
Upvotes: 0