| Angular-Configurations | Angular Router Outlet | |
In Angular 17+ : Modular Configuration |
app.config.ts & app.config.server.ts
The modular configuration files app.config.ts and app.config.server.ts
were introduced in Angular 17 as part of the framework’s push toward
standalone components and server-side rendering (SSR)., platform-specific bootstrapping, and cleaner application setup.
Angular 17 introduced:
bootstrapApplication() as the preferred way to start apps (replacing NgModule-based bootstrapping).ApplicationConfig interface to centralize providers.provideServerRendering().These changes encouraged developers to split configuration logic into:
app.config.ts → for browser/client-side setup.app.config.server.ts → for server-side rendering (SSR) setup.This modular approach became even more prominent in Angular 18 and 20.
This file defines the application configuration for the browser platform.
It’s used when bootstrapping the app with bootstrapApplication() in main.ts.
main.ts.// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideRouter, withInMemoryScrolling } from '@angular/router';
import { provideHttpClient } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { appRoutes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [
provideAnimations(),
provideHttpClient(),
provideRouter(
appRoutes,
withInMemoryScrolling({ scrollPositionRestoration: 'enabled' })
)
]
};
// main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { appConfig } from './app/app.config';
bootstrapApplication(AppComponent, appConfig)
.catch(err => console.error(err));
This file is used when bootstrapping the app for server-side rendering (e.g., Angular Universal). It allows you to override or extend the client config with SSR-specific providers.
provideServerRendering().// app.config.server.ts
import { ApplicationConfig } from '@angular/core';
import { appConfig } from './app.config';
import { provideServerRendering } from '@angular/platform-server';
export const serverConfig: ApplicationConfig = {
...appConfig,
providers: [
...appConfig.providers,
provideServerRendering()
]
};
// main.server.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { serverConfig } from './app/app.config.server';
bootstrapApplication(AppComponent, serverConfig)
.catch(err => console.error(err));
| Feature | app.config.ts | app.config.server.ts |
|---|---|---|
| Target Platform | Browser | Server (SSR) |
| Bootstrapping Method | main.ts |
main.server.ts |
| Providers Included | Animations, Router, HTTP | All from app.config.ts + SSR |
| Modularity | High | High |
| Reusability | Across environments | With overrides for SSR |
Given your modular teaching style and focus on runtime mechanics, you can extend this pattern by creating:
app.config.testing.ts for test environments.app.config.multi-tenant.ts with dynamic providers based on tenant metadata.APP_INITIALIZER for external JSON configs. | Angular-Configurations | Angular Router Outlet | |