Angular 9 : Error NG2003: No suitable injection token for parameter ‘url’ of class ‘DataService’. Found string

In DataService.ts :

Update the Constructor.

//import { Inject } from '@angular/core';

constructor(@Inject(String) private url: string, private http: Http)

UPDATED (Explanation):

According to https://angular-2-training-book.rangle.io/di/angular2/inject_and_injectable ;

@Inject() is a manual mechanism for letting Angular know that a parameter must be injected.

@Inject decorator is only needed for injecting primitives.

The primitive types are number, string, boolean, bigint, symbol, null, undefined.

The other (alternative) way can be used is:

//import { Inject } from '@angular/core';

@Inject('url') private url: string;

Leave a Comment

tech