Error "No provider for HttpClient" in Angular: causes and fix
Hello everyone! I'm a beginner in Angular and TypeScript. I'm creating a simple application that should receive data from a server via HTTP. I generated a service using Angular CLI and added HttpClient to it. But when I run the application, the following error appears in the browser console:
```
NullInjectorError: No provider for HttpClient!
```
My service looks like this (`data.service.ts` file):
```typescript
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor(private http: HttpClient) { }
getUsers() {
return this.http.get('https://jsonplaceholder.typicode.com/users');
}
}
```
And the component that uses the service (`app.component.ts` file):