Sub topic 1
What the Angular CLI Does and How to Install It
The Angular CLI is a command-line tool for creating, developing, testing, and building Angular applications. It generates consistent files and runs the Angular build system for you. This chapter assumes basic TypeScript, HTML, CSS, Node.js, npm, and terminal usage.
Prerequisites
You need Node.js and npm installed. Check them with:
node --version
npm --versionInstall the Angular CLI globally, then create and start a workspace:
npm install -g @angular/cli
ng new my-app
cd my-app
ng serveng new asks configuration questions, such as whether to enable routing and which stylesheet format to use. It creates a workspace, which is the directory containing the application and its configuration. ng serve starts a development server and rebuilds the application when source files change.
> callout note > Use a CLI version compatible with the Angular version used by your project. ng version reports the installed CLI and framework versions.
Workspace Root Files
The workspace root contains project-wide configuration:
angular.jsondefines build, serve, test, and other targets.package.jsonlists npm scripts and dependencies.package-lock.jsonrecords the exact dependency versions installed.tsconfig.jsoncontains shared TypeScript settings.tsconfig.app.jsoncontains settings for application code.README.mddocuments basic project commands.
Inside the `src` Folder
The src folder contains application source code and static resources:
main.tsis the browser entry point.app/contains the root component, routes, and application configuration.index.htmlis the page that receives the Angular application.styles.csscontains global styles.assets/commonly contains files such as images and icons.
How the Application Starts
The startup path is:
main.ts calls bootstrapApplication. Bootstrapping means creating the initial Angular application and rendering its root component.
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';
bootstrapApplication(AppComponent, appConfig)
.catch((err) => console.error(err));app.config.ts collects application-wide providers, such as the router:
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [provideRouter(routes)],
};A standalone component declares its own imports instead of belonging to an Angular module. The root component is the first standalone component rendered by bootstrapApplication.
Exercise
Which file starts the Angular application, and what does app.config.ts provide?
Show answer
main.ts starts the application by calling bootstrapApplication. app.config.ts supplies application-wide providers, such as routing.