Master Angular From Scratch

Learn Angular with clear, interactive, and structured lessons for beginners and developers.

ANGULAR COURSE SYLLABUS
1. Angular Introduction
Angular Introduction Angular History Angular Fundamentals Angular Architecture Component-Based Angular
2. Angular Setup
Angular Setup Introduction Installing Node.js Installing Angular CLI Creating an Angular Application Angular Project Structure
3. Components
Components Overview Component Anatomy Creating Components Component Selector Component Template Component Styles Component Metadata Standalone Components Parent and Child Components Reusable Components
4. Templates
Templates Introduction Template Syntax Template Expressions Template Statements Template Reference Variables ng-template ng-container ngTemplateOutlet Built-in Control Flow
5. Data Binding
Data Binding Introduction Interpolation Binding Property Binding Event Binding Two-Way Data Binding Class & Style Binding
6. Directives
Directives Introduction Attribute Directives Structural Directives Custom Directives
7. Pipes
Pipes Introduction Built-in Pipes Parameterized Pipes Chaining Pipes Custom Pipes
8. Event Handling
Event Handling Introduction DOM Events Event Binding Syntax Event Object Passing Data to Event Handlers
9. Input & Output
Component Communication @Input @Output EventEmitter
10. Lifecycle Hooks
Lifecycle Hooks Introduction ngOnInit ngOnChanges ngAfterViewInit ngOnDestroy
11. Services
Services Introduction Creating Angular Services Using Services in Components Sharing Data Through Services Service Scope
12. Dependency Injection
Dependency Injection Introduction Injecting Dependencies InjectionToken Provider Configuration
13. Routing
Routing Introduction Route Configuration RouterLink & Navigation Route Parameters Child Routes Route Guards
14. Forms
Angular Forms Introduction Template-Driven Forms Reactive Forms Form Validation Form Submission & Error Handling
15. HttpClient
HttpClient Introduction Configuring HttpClient GET Request POST, PUT & DELETE Requests Headers & Parameters HTTP Error Handling
16. Observables
Observables Introduction Creating & Subscribing to Observables Observable Data Streams Observable Operators Subscription Management
17. RxJS
RxJS Introduction RxJS Operators Transformation & Filtering Combining Observables Higher-Order Mapping Subjects
18. API Integration
API Integration Introduction Connecting Angular with REST API Consuming API Data CRUD API Integration API Response & Error Handling

Creating Angular Components

Angular components can be created manually or by using Angular CLI. Angular CLI is the recommended approach because it automatically creates the required component files and configuration.

What Does Creating a Component Mean?

Creating a component means creating a reusable part of the Angular user interface with its own logic, template and styling.

For example, in a Student Management application we can create a separate component for displaying student information.

Example: Student Component → Displays Student Information

Component Creation Flow

1
Angular Project

Open the Angular application.

→
2
Angular CLI

Generate a component using CLI.

→
3
Component Files

Angular creates component files.

→
4
Use Component

Use the component in the application.

Prerequisite

Before creating a component, make sure you have an Angular application and Angular CLI available.

Terminal
ng version
Check Your Project

Run Angular CLI commands from inside your Angular project directory.

Creating a Component Using Angular CLI

The Angular CLI provides the ng generate component command to create a new component.

Terminal Command
ng generate component student

The short version of the same command is:

Short Command
ng g c student

Understanding the Command

ng
Angular CLI

Angular CLI command-line interface.

generate
Generate

Tells Angular CLI to generate something.

component
Component

Specifies that a component should be created.

student
Component Name

Name of the component being created.

Files Generated by Angular CLI

Depending on the Angular version and project configuration, Angular CLI generates the required files for the component.

Generated Component
student/
├── student.component.ts
├── student.component.html
├── student.component.css
└── student.component.spec.ts

Component TypeScript File

The TypeScript file contains the component class and its logic.

student.component.ts
import { Component } from '@angular/core';

@Component({
    selector: 'app-student',
    templateUrl: './student.component.html',
    styleUrl: './student.component.css'
})
export class StudentComponent {

    studentName = 'Sam';

}

Component HTML Template

The HTML template defines the user interface of the component.

student.component.html
<h2>Student Details</h2>

<p>
    Student Name: {{ studentName }}
</p>

Component CSS

The component stylesheet can be used to customize the appearance of the component.

student.component.css
h2 {
    color: #4c1d95;
}

p {
    font-size: 18px;
}

Using the Created Component

After creating the component, its selector can be used in another Angular template.

app.component.html
<h1>CIIT Student Management</h1>

<app-student></app-student>

Expected Output

CIIT Student Management


Student Details

Student Name: Sam

Creating a Component for Pradnya

We can create another component using the same Angular CLI command with a different name.

Terminal
ng generate component student-profile

The component can then contain student profile information.

Reusing a Component

A component can be used wherever its selector is available in the Angular application.

Student Component
↓
Student List
Student Details
Student Dashboard

Common Mistakes

1. Running the command outside the project

Make sure the terminal is opened inside the Angular project directory.

2. Using an incorrect selector

Make sure the selector used in the HTML matches the selector defined in the component metadata.

3. Incorrect component name

Use meaningful component names such as student, student-profile or student-list.

Complete Component Creation Flow

1
Open Project CIITStudentApp
→
2
Run CLI ng generate component
→
3
Files Created TS + HTML + CSS
→
4
Use Component app-student
→
5
Browser Displays UI

Summary

Angular components can be created easily using Angular CLI. The command ng generate component creates the required component files.

A component normally contains TypeScript logic, an HTML template and styling.

After creating a component, its selector can be used inside an Angular template to display the component.