Sub topic 2
The Root Component and Standalone Components
Assume you know basic TypeScript, HTML, CSS, Node.js, npm, and terminal commands. In modern Angular, a standalone component declares its own imports. It does not need to belong to an NgModule.
How the application starts
The root component is the first component Angular renders. main.ts bootstraps it with application-wide configuration:
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { appConfig } from './app/app.config';
bootstrapApplication(AppComponent, appConfig)
.catch((error) => console.error(error));app.config.ts commonly registers the router and other providers:
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [provideRouter(routes)],
};Route configuration
app.routes.ts maps URL paths to components. A route can load a component only when its path is visited:
import { Routes } from '@angular/router';
import { ProductListComponent } from './products/product-list.component';
export const routes: Routes = [
{ path: 'products', component: ProductListComponent },
{ path: '', redirectTo: 'products', pathMatch: 'full' },
];The root template usually contains <router-outlet />, which marks where the selected route appears.
Reading `angular.json`
angular.json defines workspace projects and CLI targets such as build, serve, and test. Each target has shared options and named configurations.
{
"architect": {
"build": {
"builder": "@angular/build:application",
"options": { "browser": "src/main.ts" },
"configurations": {
"development": { "optimization": false, "sourceMap": true }
}
}
}
}Edit this file carefully. A configuration changes CLI behavior, but it does not replace application code.
TypeScript configuration
The root tsconfig.json contains shared compiler settings. tsconfig.app.json adds application source files, while tsconfig.spec.json covers test files. Keeping these scopes separate prevents test-only settings from affecting production builds.
Generate application code
Use generators instead of creating repetitive files manually:
ng generate component products/product-list
ng generate service products/product
ng build --configuration developmentThe CLI creates files, updates metadata when needed, and follows Angular naming conventions.
Exercise
Which file connects the root component with application-wide providers?
Show answer
main.ts passes appConfig to bootstrapApplication, and app.config.ts defines those providers.