Provide HttpClient in root

Until Angular v21, the HttpClient service had to be explicitly provided in the root of the application, in the app.config.ts file.

Creating a new project starting with Angular v21 will automatically provide the HttpClient service.

Under the hood, Angular added {providedIn: 'root'} to the HttpClient service:

@Injectable({providedIn: 'root'})
export class HttpClient {
...
}

Exercise

The app relies on the HttpClient service to fetch the upcoming event from Angular HUB.

Remove the provideHttpClient from the app.config.ts file.

export const appConfig: ApplicationConfig = {
providers: [
provideBrowserGlobalErrorListeners(),
provideRouter(routes),
provideHttpClient(),
],
};

The app should still work.

Powered by WebContainers
Files
Preparing Environment
  • Installing dependencies
  • Start the application