Angular Environment Setup & Your First App
Install the Angular CLI, scaffold your first project, understand the workspace structure, and run your app in development mode. The complete beginner starting point.
Angular is a full-featured, opinionated frontend framework built on TypeScript. It handles routing, forms, HTTP, state management, and testing out of the box ā no need to assemble a stack yourself. This lesson gets you from zero to a running app in under 30 minutes.
Prerequisites
- Node.js 18 or later (check with
node -v) - npm 9+ (comes with Node) or yarn
- Basic TypeScript knowledge helps but is not required
Install the Angular CLI
The Angular CLI (ng) is how you create, build, serve, and test Angular apps.
npm install -g @angular/cliVerify installation:
ng versionYou should see Angular CLI version 17+ and your Node/npm versions.
Create a New Project
ng new my-first-appThe CLI asks two questions:
- Would you like to add Angular routing? ā Yes
- Which stylesheet format? ā CSS (or SCSS if you prefer)
This scaffolds a complete project. The --standalone architecture is the default in Angular 17+ ā no NgModule boilerplate needed.
cd my-first-app
ng serveOpen http://localhost:4200. You'll see the Angular welcome page. The dev server watches for file changes and hot-reloads automatically.
Project Structure
my-first-app/
āāā src/
ā āāā app/
ā ā āāā app.component.ts ā Root component (logic)
ā ā āāā app.component.html ā Root component (template)
ā ā āāā app.component.css ā Root component (styles)
ā ā āāā app.component.spec.ts ā Root component (tests)
ā ā āāā app.config.ts ā App-level providers (routing, HTTP)
ā āāā main.ts ā Entry point ā bootstraps the app
ā āāā index.html ā Shell HTML ā lives here
āāā angular.json ā CLI config (build, serve, test options)
āāā tsconfig.json ā TypeScript config
āāā package.json Key files:
main.ts ā bootstraps the root component:
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';
bootstrapApplication(AppComponent, appConfig).catch(console.error);app.config.ts ā register global providers (routing, HTTP client):
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideHttpClient } from '@angular/common/http';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideHttpClient(),
],
};Your First Component
Open app.component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-root', // HTML tag: <app-root>
standalone: true, // no NgModule needed
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
title = 'my-first-app';
count = 0;
increment() {
this.count++;
}
}Update app.component.html:
<h1>Hello, {{ title }}!</h1>
<p>Count: {{ count }}</p>
<button (click)="increment()">Click me</button>Save the file ā the browser updates instantly. This is one-way data binding ({{ }}) and event binding ((click)). You'll learn all binding forms in the next lesson.
Generate Files with the CLI
Don't create files manually ā use the CLI. It generates the right file structure and wires things up:
# Generate a component
ng generate component features/user-profile
# Short form:
ng g c features/user-profile
# Generate a service
ng g s services/auth
# Generate a pipe
ng g p pipes/truncateGenerated files follow a consistent naming convention: feature-name.component.ts, feature-name.service.ts, etc.
Useful CLI Commands
ng serve # Start dev server (port 4200)
ng serve --port 4201 # Custom port
ng build # Production build ā dist/
ng build --configuration=production # Explicit prod build
ng test # Run unit tests (Karma + Jasmine)
ng lint # Run ESLint
ng generate component <name> # New component
ng generate service <name> # New service
ng generate guard <name> # New route guard
ng add @angular/material # Add Angular Material UI libraryStandalone vs. Module-based
Angular 17+ defaults to standalone components ā components declare their own imports instead of being registered in an NgModule. This is the modern approach and what this course uses.
// Standalone (modern ā Angular 17+)
@Component({
selector: 'app-user',
standalone: true,
imports: [CommonModule, RouterLink], // imports go here
template: `...`,
})
export class UserComponent {}Older codebases use NgModule. You'll encounter both, but standalone is the direction Angular is headed.
VS Code Setup
Install these extensions for the best Angular experience:
- Angular Language Service ā template autocomplete, type checking in HTML
- ESLint ā code quality
- Prettier ā code formatting
- Angular Snippets ā code snippets
Quick Reference
Install CLI: npm install -g @angular/cli
New project: ng new project-name
Dev server: ng serve ā localhost:4200
New component: ng g c component-name
New service: ng g s service-name
Build: ng build
Test: ng test
Config file: angular.json
Entry point: src/main.ts
Root component: src/app/app.component.tsFound this helpful?
Leave a comment
Have a question, correction, or just found this helpful? Leave a note below.