Angular 5: Can't resolve all parameters for Service

Your DataService service has two constructor parameters, url and http. http can be resolved because it is registered by the HttpClientModule, but the url parameter is not registered in the dependency injection container. That is the reason why you get the error.

I guess you always let inject a specific class, as for example UserDataService, into your components and never a DataService instance.

So you should refactor your DataService to an abstract DataServiceBase class and remove the @Injectable() decorator.

And as yurzui suggested, remove DataService from the list of providers.


The error indicates that the first argument in the constructor is causing the problem. And it should because it's a simple string. Try injecting it like this:

@Injectable()
export class DataService {

constructor(@Inject('API_BASE_URL') private url: string, private http: HttpClient) { // ... }

In your providers:

providers: [DataService, {provide: 'API_BASE_URL', useValue: 'http://localhost:8080/users'}]

I had exactly same error. I solved it by removing DataService from providers: [] and also removing the @Injectable decorator from DataService.