This README walks you through setting up an Angular application (standalone or module-based), including CLI usage and file structure. Separate .ts, .html, and .css files are used for each component.
Install globally (make sure node & npm are installed):
npm install -g @angular/cli
ng version
Standalone (default for Angular 17+)
ng new my-angular-app
cd my-angular-app
NgModule‑based (legacy/project need)
ng new my-angular-app --no-standalone
cd my-angular-app
This creates app.module.ts as the main module file
Workspace/layout generated by CLI: includes angular.json, package.json, tsconfig.json, .gitignore, etc. Angular
Key src/ subfolders:
component-name/
├── component-name.component.ts
├── component-name.component.html
├── component-name.component.css
└── component-name.component.spec.ts
Each generated component will have:
.ts(TypeScript logic).html(template).css(styling).spec.ts(tests)
All in separate files for clean structure.
| Type | Description |
|---|---|
| Standalone | Modular, self-contained. No NgModule needed. Default in Angular 17+. |
| NgModule-based | Traditional. Uses root and feature modules for grouping app functionality. |
Run these commands within your project directory (cd my-angular-app).
1. Generate a Component
Creates component with .ts, .html, .css, .spec.ts:
components/— Reusable UI components (each in its own folder)services/— Business logic and shared datamodels/— TypeScript interfaces and typescore/— Singleton services, guards, interceptors, etc.shared/— Modules and components shared across the apppages/— Page-level or feature views
| Purpose | Command | Notes |
|---|---|---|
| New App | ng new my-app |
Separate .html, .ts, .css files |
| New Standalone Component | ng g c hero --standalone |
Default (Angular 17+) |
| New Module-based Component | ng g c hero --module app |
For NgModule/app module approach |
| New Service | ng g s hero |
Service in src/app |
| Feature | Standalone | NgModule-based |
|---|---|---|
| Registration | No NgModule required | Use declarations in NgModule |
| Imports | Import per-component | Group via NgModule imports |
| Use Case | Modern, modular apps | Large apps, shared features |
| CLI Support | Default (Angular 17+) | Still fully supported |