Set up an Angular project with the Angular CLI, write your first component using decorators, and master template syntax including ngIf, ngFor, and two-way
Generate a component with the CLI — it creates all four files and registers it automatically:
Angular uses its own CLI to scaffold projects. Every Angular project is TypeScript-first by design — you get type checking, autocomplete, and refactoring tools out of the box.
npm install -g @angular/cli ng new my-app --routing --style=css cd my-app ng serve
Open http://localhost:4200. The project structure has a clear separation of concerns:
src/ ├── app/ │ ├── app.component.ts ← root component │ ├── app.component.html ← root template │ ├── app.module.ts ← root module │ └── app-routing.module.ts └── main.ts
Generate a component with the CLI — it creates all four files and registers it automatically:
ng generate component greeting # or shorthand: ng g c greeting
import { Component } from '@angular/core';
@Component({
selector: 'app-greeting', // used as in templates
templateUrl: './greeting.component.html',
styleUrls: ['./greeting.component.css']
})
export class GreetingComponent {
title = 'Hello, Angular';
name = '';
items: string[] = ['Apples', 'Bananas', 'Cherries'];
addItem(item: string) {
this.items.push(item);
}
}
{{ title }}
Hello, {{ name }}!
0">Name is set!
FormsModule to your app.module.ts imports array. Forgetting this is the #1 Angular beginner mistake.// In the component class:
disabled = true;
imageUrl = 'https://example.com/img.png';
onClick() { console.log('clicked'); }
Before moving on, confirm understanding of these key concepts: