English
Creating the project
Step 1. Angular for a C# developer
Why. Everything so far ran on the server. The client runs in the browser, and browsers run JavaScript. Chatex writes it in TypeScript — JavaScript with static types, compiled to JavaScript — and structures it with Angular, a complete framework from Google: components, routing, forms, an HTTP client, dependency injection and a build system in one package. Its alternatives, React and Vue, are libraries around which every team assembles its own set of tools; for a C# developer Angular is the most familiar choice, because it has a DI container, services, attributes (decorators) and a strict compiler.
Table 15.1 maps the Angular vocabulary to what you know from .NET.
Table 15.1. Angular terms and their .NET counterparts
| Angular | .NET | What it is |
|---|---|---|
npm, package.json, package-lock.json | NuGet, Directory.Packages.props, packages.lock.json | packages, their versions and the exact resolved tree |
angular.json | .csproj, Directory.Build.props | how the project is built, served, tested and linted |
tsconfig.json | compiler settings in the project file | TypeScript compiler options |
component (@Component class + template) | Razor component | a piece of the user interface with its state |
service (@Injectable) | a class registered in IServiceCollection | logic and state shared by components |
inject(T) | constructor injection | getting a dependency from the DI container |
Observable<T>, Promise<T> | IObservable<T>, Task<T> | asynchronous results |
| signal | a property that raises PropertyChanged | a value that tells its readers when it changes |
Modern Angular (version 22 here) differs from the Angular of older tutorials in three ways that this module uses everywhere:
- Standalone components. A component lists the components, directives and pipes its template uses in its own
importsarray. There are noNgModuleclasses. - Signals. State is kept in signals — values that notify their readers — instead of plain fields that Angular has to compare.
- Zoneless change detection. Angular no longer patches every browser API with the
zone.jslibrary to guess when something might have changed. It re-renders a component when a signal it reads changes, when an event handler of its template runs, or when it is told to. Step 4 of the skeleton chapter explains this.
Node.js and npm
The Angular tools run on Node.js, which you installed in topic 2; the browser never sees Node.js. npm (Node Package Manager) comes with it. npm install reads package.json, downloads the packages into the folder node_modules and records the exact versions in package-lock.json; npm ci installs exactly what the lock file says, the way CI does. npx <tool> runs a tool from node_modules, or downloads it for one run.
Step 2. Create the workspace
Why. The Angular CLI (@angular/cli) creates a workspace: the folder with the configuration, the packages and a first application. We run it once with npx, so nothing is installed globally, and pin its version so that you get the same files as the reference.
Do. From the repository root:
powershell
npx @angular/[email protected] new chatex --directory Source/Chatex.Web --style tailwind --ssr=false --zoneless --ai-config none --skip-git --interactive=falseThe options are explained in Table 15.2.
Table 15.2. Options of ng new
| Option | Meaning |
|---|---|
chatex | the name of the workspace and the project; it becomes the build target chatex and the output folder dist/chatex |
--directory Source/Chatex.Web | create the workspace next to the .NET projects instead of in ./chatex |
--style tailwind | use Tailwind CSS: installs tailwindcss and @tailwindcss/postcss and writes .postcssrc.json |
--ssr=false | no server-side rendering; the API serves JSON, and Nginx serves the built files (topic 24) |
--zoneless | no zone.js: change detection is driven by signals (the default for new projects; we make it explicit) |
--ai-config none | no configuration files for AI coding assistants |
--skip-git | do not create a Git repository: we are already inside one |
--interactive=false | ask no questions; everything not given uses its default (for example routing and Vitest) |
The CLI prints the files it creates and installs the packages:
CREATE Source/Chatex.Web/.prettierrc (173 bytes)
CREATE Source/Chatex.Web/angular.json (1976 bytes)
CREATE Source/Chatex.Web/package.json (875 bytes)
CREATE Source/Chatex.Web/README.md (1518 bytes)
CREATE Source/Chatex.Web/tsconfig.json (939 bytes)
CREATE Source/Chatex.Web/.editorconfig (331 bytes)
CREATE Source/Chatex.Web/.gitignore (666 bytes)
CREATE Source/Chatex.Web/tsconfig.app.json (412 bytes)
CREATE Source/Chatex.Web/tsconfig.spec.json (423 bytes)
CREATE Source/Chatex.Web/.postcssrc.json (57 bytes)
CREATE Source/Chatex.Web/.vscode/extensions.json (134 bytes)
CREATE Source/Chatex.Web/.vscode/launch.json (490 bytes)
CREATE Source/Chatex.Web/.vscode/tasks.json (1020 bytes)
CREATE Source/Chatex.Web/src/main.ts (228 bytes)
CREATE Source/Chatex.Web/src/index.html (305 bytes)
CREATE Source/Chatex.Web/src/styles.css (105 bytes)
CREATE Source/Chatex.Web/src/app/app.spec.ts (704 bytes)
CREATE Source/Chatex.Web/src/app/app.ts (301 bytes)
CREATE Source/Chatex.Web/src/app/app.css (0 bytes)
CREATE Source/Chatex.Web/src/app/app.html (20488 bytes)
CREATE Source/Chatex.Web/src/app/app.config.ts (322 bytes)
CREATE Source/Chatex.Web/src/app/app.routes.ts (80 bytes)
CREATE Source/Chatex.Web/public/favicon.ico (15086 bytes)
- Installing packages (npm)...
✔ Packages installed successfully.Table 15.3 shows what each generated file is for and what happens to it in this module.
Table 15.3. The generated files
| File | Purpose | In Chatex |
|---|---|---|
package.json, package-lock.json | packages and npm scripts | extended in step 3 |
angular.json | build, serve, test and lint targets | extended in step 4 |
tsconfig*.json | TypeScript settings for the app and the tests | tsconfig.app.json changes in step 4 |
.prettierrc, .postcssrc.json | Prettier and Tailwind (PostCSS) settings | Prettier gets a plugin in the next chapter |
.vscode/* | recommended extension, debug and task settings | the ng test debug configuration goes (next chapter) |
src/index.html, src/main.ts, src/styles.css | the page, the entry point, the global styles | replaced in the next chapters |
src/app/app.ts, app.html, app.css, app.spec.ts | the root component with a welcome page, and its test | replaced and deleted in the skeleton chapter |
src/app/app.config.ts, app.routes.ts | the application's providers and its routes | kept for now; topics 16 and 17 replace them |
.editorconfig, .gitignore | editor and Git settings for a stand-alone repository | deleted now: the repository root has both |
public/favicon.ico | static files copied to the output as they are | joined by more icons later in this topic |
Do. Delete the two files that the repository root already covers. The root .editorconfig has a section for Source/Chatex.Web/**, and the root .gitignore ignores node_modules/, dist/ and .angular/ (topic 2):
powershell
Remove-Item Source/Chatex.Web/.editorconfig, Source/Chatex.Web/.gitignoreLine endings
On Windows the CLI writes most files with CRLF line endings. The repository stores LF (.gitattributes, topic 2), and Prettier, which we add in the next chapter, insists on LF. The files you replace with listings get LF anyway; the few generated files we keep are normalised once by npm run format in the next chapter.
Step 3. The packages
Why. ng new installed Angular, TypeScript, Tailwind, Prettier and Vitest. Chatex needs a few more packages (Table 15.4).
Table 15.4. The packages added to the generated workspace
| Package | Kind | What for |
|---|---|---|
angular-eslint, eslint, @eslint/js, typescript-eslint | development | linting TypeScript and Angular templates (ng lint) |
prettier-plugin-tailwindcss | development | Prettier sorts Tailwind classes in a fixed order |
@angular/cdk | runtime | the Component Dev Kit: dialogs, menus, overlays, clipboard (topic 17 onwards) |
@lucide/angular | runtime | the Lucide icon set as Angular components |
@microsoft/signalr | runtime | the SignalR client for the hub of topic 14 (topic 20) |
Do. Run the following commands in Source/Chatex.Web:
powershell
Set-Location Source/Chatex.WebESLint is added with ng add, which installs the packages and runs the library's set-up schematic: it writes eslint.config.js, adds the lint target to angular.json and the lint script to package.json:
powershell
npx ng add angular-[email protected] --skip-confirmationCREATE eslint.config.js (1004 bytes)
UPDATE package.json (1020 bytes)
UPDATE angular.json (2187 bytes)
✔ Packages installed successfully.The other packages are plain npm packages:
powershell
npm install @angular/[email protected] @lucide/[email protected] @microsoft/[email protected]powershell
npm install -D prettier-plugin-[email protected]Finally, add the two Prettier scripts and the Node.js version to package.json by hand. The complete file:
json
{
"name": "chatex",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"lint": "ng lint",
"format": "prettier --write \"src/**/*.{ts,html,css}\"",
"format:check": "prettier --check \"src/**/*.{ts,html,css}\""
},
"private": true,
"packageManager": "[email protected]",
"engines": {
"node": ">=24"
},
"dependencies": {
"@angular/cdk": "^22.2.6",
"@angular/common": "^22.2.0",
"@angular/compiler": "^22.2.0",
"@angular/core": "^22.2.0",
"@angular/forms": "^22.2.0",
"@angular/platform-browser": "^22.2.0",
"@angular/router": "^22.2.0",
"@lucide/angular": "^1.72.0",
"@microsoft/signalr": "^11.0.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0"
},
"devDependencies": {
"@angular/build": "^22.2.6",
"@angular/cli": "^22.2.6",
"@angular/compiler-cli": "^22.2.0",
"@eslint/js": "^10.0.1",
"@tailwindcss/postcss": "^4.1.12",
"angular-eslint": "22.6.0",
"eslint": "^10.12.0",
"jsdom": "^30.0.0",
"postcss": "^8.5.3",
"prettier": "^3.8.1",
"prettier-plugin-tailwindcss": "^0.8.1",
"tailwindcss": "^4.1.12",
"typescript": "~6.0.2",
"typescript-eslint": "8.71.0",
"vitest": "^5.0.0"
}
}scriptsare the commands of the project:npm startrunsng serve,npm run buildrunsng build,npm testrunsng test, and so on.Run.ps1and the CI workflow (topic 22) call exactly these scripts.formatrewrites the files,format:checkonly reports — that is what CI runs.enginesdocuments that the project needs Node.js 24 or newer.packageManagerwas written byng newwith the npm version it found; yours may show another version.- Version ranges.
^22.2.0allows any later 22.x version,~7.8.0any later 7.8.x;angular-eslintandtypescript-eslintare pinned exactly byng add. The ranges say what is acceptable; the lock file says what is installed.
Do. npm install resolved the newest versions within these ranges, which may already be newer than the reference's. To build with exactly the versions of the reference — as Directory.Packages.props pinned the NuGet versions in topic 2 — copy its lock file and install from it:
powershell
Copy-Item D:\Work\Chatex-Reference\Source\Chatex.Web\package-lock.json .powershell
npm cinpm ci deletes node_modules and installs exactly the tree of package-lock.json. From now on, ./Run.ps1 setup does the same on a fresh clone.
Check
powershell
npm ls --depth=0lists the 26 direct packages, for example @angular/[email protected], @angular/[email protected], @microsoft/[email protected] and [email protected], without errors.
Step 4. The workspace configuration
Why. angular.json describes the targets of the project — build, serve, test and lint — and the options of the builders that run them. The generated file needs five changes for Chatex.
Do. Replace angular.json:
json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"cli": {
"packageManager": "npm",
"schematicCollections": [
"angular-eslint"
],
"analytics": false
},
"newProjectRoot": "projects",
"projects": {
"chatex": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "none"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular/build:application",
"options": {
"browser": "src/main.ts",
"tsConfig": "tsconfig.app.json",
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
"styles": [
"node_modules/@angular/cdk/overlay-prebuilt.css",
"src/styles.css"
]
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "700kB",
"maximumError": "1.2MB"
},
{
"type": "anyComponentStyle",
"maximumWarning": "4kB",
"maximumError": "8kB"
}
],
"outputHashing": "all",
"optimization": {
"scripts": true,
"styles": {
"minify": true,
"inlineCritical": false
},
"fonts": true
}
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular/build:dev-server",
"configurations": {
"production": {
"buildTarget": "chatex:build:production"
},
"development": {
"buildTarget": "chatex:build:development"
}
},
"defaultConfiguration": "development",
"options": {
"proxyConfig": "proxy.conf.json"
}
},
"test": {
"builder": "@angular/build:unit-test"
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"src/**/*.ts",
"src/**/*.html"
]
}
}
}
}
}
}Compared with the generated file:
cli.analytics: false— the CLI does not ask to send usage statistics.schematicCollectionswas added byng add angular-eslint.schematics—ng generate componentcreates components without a style file. Chatex styles everything with Tailwind classes in the templates.styles— the prebuilt CSS of the CDK overlay comes before our styles: dialogs and menus (topic 17) are positioned by it.budgets— the build warns when the initial download grows over 700 kB and fails over 1.2 MB. The generated limits (500 kB and 1 MB) are too tight for an application with SignalR and the CDK.optimization.styles.inlineCritical: false— by default the production build inlines the CSS needed for the first paint and loads the rest with a small inline script. The production Content-Security-Policy (topic 24) allows only scripts from our own files,script-src 'self', so that loader would be blocked. Switching the inlining off keeps the page free of inline scripts.serve.options.proxyConfig— the development server forwards API calls to the backend (the skeleton chapter).lint— added byng add angular-eslint; the reference lists the patterns one per line.
The three tsconfig files stay as generated except for one line. tsconfig.json holds the common, strict settings (Table 15.5), tsconfig.app.json compiles the application, tsconfig.spec.json the tests. Exclude the test helpers that topic 16 puts into src/testing from the application build:
json
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": []
},
"include": [
"src/**/*.ts"
],
"exclude": [
"src/**/*.spec.ts",
"src/testing/**"
]
}Table 15.5. Notable compiler settings of tsconfig.json
| Setting | Effect |
|---|---|
strict (on by default since TypeScript 6, so the file does not mention it) | null and undefined are separate types, as with nullable reference types in C#, and implicit any is an error: const x: string = null fails with TS2322 |
noPropertyAccessFromIndexSignature | keys of a dictionary-like type must be read as errors['required'], not errors.required |
noImplicitReturns, noFallthroughCasesInSwitch | every code path returns, and case blocks do not fall through by accident |
strictInjectionParameters, strictInputAccessModifiers | Angular's compiler checks DI tokens and component inputs as strictly |
target: ES2022, module: preserve | modern JavaScript output; the bundler, not TypeScript, resolves the imports |
Check
The generated application still builds:
powershell
npm run buildThe output ends with Application bundle generation complete and the folder dist/chatex/browser.