No suitable injection token

If you get the following error:

No suitable injection token for parameter ‘url’ of class ‘DataService’. Consider using the @Inject decorator to specify an injection token.

Course: Angular 4: Beginner to Pro
Section: Consuming HTTP Services
Video: 18- Extracting a Reusable Data Service

Then, you may be working with code that looks like this:

  constructor( private url: string, private http: HttpClient) { }

So, you’ll just need to follow the instructions from the second sentence of the error: Add the @Inject(String) decorator.

  constructor(@Inject(String) private url: string, private http: HttpClient) { }

Your code should compile now. :smile:

3 Likes