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

Angular API Integration

Learn how Angular applications connect with backend APIs, send requests, receive responses and work with application data.

What is API Integration?

API Integration means connecting an Angular application with a backend service so that the application can send and receive data.

Angular applications commonly communicate with REST APIs using HttpClient.

API integration allows the frontend to work with real application data instead of depending only on static values.

Angular API Communication Flow

Angular Component User Action
→
Service HttpClient
→
REST API Backend Server
→
Response JSON Data

Why Use APIs?

D
Dynamic Data

Load data from a backend instead of hard-coded values.

C
Centralized Data

Frontend and backend can work with the same application data.

R
Real Applications

Build applications that communicate with databases and backend services.

S
Separation

Frontend presentation and backend business logic can remain separate.

What is a REST API?

A REST API exposes backend resources through HTTP endpoints that clients can communicate with.

Angular sends an HTTP request to an endpoint and receives a response from the backend service.

Example Endpoint
GET /api/courses

Angular HttpClient

Angular provides HttpClient for making HTTP requests to backend services.

HttpClient methods return Observable-based results that can be consumed by Angular components and services.

Import HttpClient
import {
    HttpClient
} from '@angular/common/http';

API Integration Through a Service

API communication is commonly placed inside an Angular service instead of directly writing all HTTP logic inside the component.

This keeps components focused on presentation and application interaction while the service handles communication.

Course Service
import { Injectable } from '@angular/core';

import {
    HttpClient
} from '@angular/common/http';

@Injectable({
    providedIn: 'root'
})
export class CourseService {

    private apiUrl =
        '/api/courses';

    constructor(
        private http: HttpClient
    ) {
    }


    getCourses() {

        return this.http.get<Course[]>(
            this.apiUrl
        );

    }

}

Consuming API Data in Component

Component
export class CoursesComponent {

    courses: Course[] = [];

    constructor(
        private courseService: CourseService
    ) {
    }


    loadCourses() {

        this.courseService
            .getCourses()
            .subscribe({

                next: courses => {

                    this.courses = courses;

                },

                error: error => {

                    console.error(error);

                }

            });

    }

}

Complete API Request Flow

User Action Load Courses
→
Component Calls Service
→
HttpClient Sends GET
→
API Returns Data

Common HTTP Methods

G
GET

Retrieve data from the backend.

P
POST

Send data to create a new resource.

U
PUT

Update an existing resource.

D
DELETE

Remove a resource from the backend.

GET Request

A GET request is used to retrieve data from an API endpoint.

HttpClient GET
getCourses() {

    return this.http.get<Course[]>(
        '/api/courses'
    );

}

POST Request

POST is commonly used when the frontend needs to send data to the backend to create a new resource.

HttpClient POST
addCourse(course: Course) {

    return this.http.post<Course>(
        '/api/courses',
        course
    );

}

PUT Request

PUT can be used to send updated data for an existing resource.

HttpClient PUT
updateCourse(
    id: number,
    course: Course
) {

    return this.http.put<Course>(
        '/api/courses/' + id,
        course
    );

}

DELETE Request

DELETE can be used to remove a resource through an API endpoint.

HttpClient DELETE
deleteCourse(id: number) {

    return this.http.delete(
        '/api/courses/' + id
    );

}

Working with API Responses

The backend commonly sends structured data such as JSON.

Angular can assign the received response to component properties and use it to update the user interface.

Example Response
[
    {
        "id": 1,
        "name": "Java Full Stack"
    },
    {
        "id": 2,
        "name": ".NET Full Stack"
    }
]

API Error Handling

API communication can fail because of network problems, invalid requests, server errors or other backend conditions.

Angular applications should handle failed requests and provide an appropriate user experience.

Example
this.courseService
    .getCourses()
    .subscribe({

        next: courses => {

            this.courses = courses;

        },

        error: error => {

            console.error(
                'API Error:',
                error
            );

        }

    });

Loading State

API requests may take time to complete. A component can maintain a loading state while waiting for the response.

This allows the interface to show the user that data is currently being loaded.

Example
loading = false;


loadCourses() {

    this.loading = true;

    this.courseService
        .getCourses()
        .subscribe({

            next: courses => {

                this.courses = courses;
                this.loading = false;

            },

            error: error => {

                console.error(error);
                this.loading = false;

            }

        });

}

CIIT Training Institute Example

Suppose the CIIT Training Institute website displays the available training courses from a backend API.

The Angular component calls a service, the service sends an HTTP request, and the API returns the course data.

API Service
@Injectable({
    providedIn: 'root'
})
export class CourseService {

    private apiUrl =
        '/api/courses';


    constructor(
        private http: HttpClient
    ) {
    }


    getCourses() {

        return this.http.get<Course[]>(
            this.apiUrl
        );

    }

}
Component
courses: Course[] = [];


loadCourses() {

    this.courseService
        .getCourses()
        .subscribe({

            next: courses => {

                this.courses = courses;

            },

            error: error => {

                console.error(error);

            }

        });

}

CIIT Training Institute Courses

Java Full Stack

.NET Full Stack

Python Full Stack

Course data loaded from API.

Frontend and Backend Architecture

Angular UI Frontend
↔
REST API Backend
↔
Database Persistent Data

API Request Overview

HTTP Method Purpose HttpClient Method
GET Retrieve data http.get()
POST Create data http.post()
PUT Update data http.put()
DELETE Delete data http.delete()

API Integration Steps

1
Create Service

Create an Angular service for API communication.

2
Inject HttpClient

Use HttpClient to communicate with the backend.

3
Call API

Use GET, POST, PUT or DELETE according to the requirement.

4
Handle Response

Subscribe to the result and update the application state.

Important Points

1. Keep API Logic in Services

Services provide a central place for backend communication.

2. Use HttpClient

HttpClient provides Angular APIs for making HTTP requests.

3. Handle API Results

Process successful responses and handle failures appropriately.

4. Keep Data Flow Organized

A clear Component → Service → API flow makes applications easier to maintain.

API Integration Best Practices

  • Keep HTTP communication inside dedicated services where practical.
  • Use meaningful API endpoint and service method names.
  • Handle loading, success and error states appropriately.
  • Define suitable TypeScript types for API responses.
  • Avoid duplicating the same API communication logic in multiple components.
  • Keep components focused on UI and application interaction.

Summary

API integration connects an Angular frontend with a backend service so that the application can work with dynamic data.

Angular commonly uses HttpClient for HTTP communication, while services can organize API-related logic.

The basic flow is Component → Service → HttpClient → REST API → Response . In the next topic, we will learn about Connecting API.