Day 01 Foundations

Components, Templates, and TypeScript

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

~1 hour Hands-on Precision AI Academy

Today's Objective

Generate a component with the CLI — it creates all four files and registers it automatically:

01

Creating an Angular Project

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.

Terminal
Terminal
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:

Project Structure
Project Structure
src/
├── app/
│   ├── app.component.ts    ← root component
│   ├── app.component.html  ← root template
│   ├── app.module.ts       ← root module
│   └── app-routing.module.ts
└── main.ts
02

Your First Component

Generate a component with the CLI — it creates all four files and registers it automatically:

Terminal
Terminal
ng generate component greeting
# or shorthand:
ng g c greeting
greeting.component.ts
greeting.component.ts
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);
  }
}
greeting.component.html
greeting.component.html

{{ title }}

Hello, {{ name }}!

Name is set!

  • {{ item }}
💡
ngModel requires FormsModule. Add FormsModule to your app.module.ts imports array. Forgetting this is the #1 Angular beginner mistake.
03

Property and Event Binding

TypeScript
TypeScript
// In the component class:
disabled = true;
imageUrl = 'https://example.com/img.png';
onClick() { console.log('clicked'); }
Template
Template









Supporting References & Reading

Go deeper with these external resources.

Docs
Components, Templates, and TypeScript Official documentation for angular.
GitHub
Components, Templates, and TypeScript Open source examples and projects for Components, Templates, and TypeScript
MDN
MDN Web Docs Comprehensive web technology reference

Day 1 Checkpoint

Before moving on, confirm understanding of these key concepts:

Continue To Day 2
Day 2 of the Angular in 5 Days course