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

Component Anatomy

An Angular component is made up of different parts that work together to create a user interface. Understanding these parts helps us create and maintain Angular applications effectively.

What is Component Anatomy?

Component anatomy means understanding the different parts of an Angular component and how those parts work together.

A component mainly contains a TypeScript class, a component decorator, a template and styling.

Component Anatomy: Decorator + Class + Template + Styles

Angular Component Anatomy

C

Angular Component

Complete UI building block

1
@Component

Provides metadata that tells Angular how to configure the component.

2
TypeScript Class

Contains properties, methods and application logic.

3
HTML Template

Defines the user interface displayed in the browser.

4
Styles

Defines the appearance of the component.

Complete Component Example

The following example shows the basic structure of a Student component.

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';

    displayMessage() {
        return 'Welcome ' + this.studentName;
    }

}

1. Import Statement

The component uses the Angular Component decorator. It is imported from Angular core.

Import
import { Component } from '@angular/core';
Purpose

The import statement makes the Component decorator available to the TypeScript class.

2. @Component Decorator

The @Component decorator provides metadata about the component.

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

3. selector

The selector defines the custom HTML element through which the component can be used.

Selector
selector: 'app-student'

The component can be placed inside another template using:

HTML
<app-student></app-student>

4. templateUrl

The templateUrl property specifies the external HTML file used by the component.

Component Metadata
templateUrl: './student.component.html'

The HTML template can contain Angular interpolation, property binding, event binding and other template features.

5. styleUrl

The styleUrl property specifies the stylesheet associated with the component.

Component Metadata
styleUrl: './student.component.css'

6. Component Class

The TypeScript class contains the data and logic required by the component.

TypeScript Class
export class StudentComponent {

    studentName = 'Sam';

    displayMessage() {
        return 'Welcome ' + this.studentName;
    }

}
Property
studentName

Stores component data.

Method
displayMessage()

Performs component logic.

7. Component Template

The HTML template defines what the user sees in the browser.

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

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

<p>
    {{ displayMessage() }}
</p>

8. Component Styling

Component-specific styles can be written in the component stylesheet.

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

p {
    font-size: 18px;
}

Expected Output

Student Details

Student Name: Sam

Welcome Sam

How Component Parts Work Together

1
Component Decorator

Defines component metadata.

→
2
TypeScript Class

Provides data and logic.

→
3
HTML Template

Displays the data.

→
4
Browser

Shows the final UI.

Component File Relationship

student.component.ts Logic
+
student.component.html UI
+
student.component.css Style
=
Student Component Complete Component

Summary

Angular component anatomy consists of the component decorator, TypeScript class, HTML template and styling.

The decorator defines component metadata such as selector, templateUrl and styleUrl.

The TypeScript class contains the component logic, while the HTML template displays the data to the user.