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 binding with ngModel.
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 serveOpen 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.tsGenerate a component with the CLI — it creates all four files and registers it automatically:
ng generate component greeting
# or shorthand:
ng g c greetingimport { 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!
- {{ item }}
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'); }
tasks component with ng g c tasks.tasks array and newTask string to the component class.*ngFor to list them.(click) event binding.*ngIf to show a 'All done!' message when all are checked.ng new and ng generate component are your primary CLI commands.{{ }} for interpolation, [prop] for property binding, (event) for event binding.[(ngModel)] = two-way binding. Requires FormsModule in your module.*ngIf and *ngFor are structural directives — they change the DOM structure.