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 CRUD Integration

Learn how Angular applications implement Create, Read, Update and Delete operations by communicating with backend REST APIs.

What is CRUD?

CRUD stands for Create, Read, Update and Delete.

These four operations represent the basic actions commonly performed on application data.

In Angular, CRUD operations are commonly implemented by using HttpClient to communicate with backend REST APIs.

CRUD Flow

Create POST
→
Read GET
→
Update PUT
→
Delete DELETE

Four CRUD Operations

C
Create

Add a new record through the backend API.

R
Read

Retrieve existing records from the backend.

U
Update

Modify an existing record.

D
Delete

Remove an existing record.

CRUD to HTTP Method Mapping

CRUD Operation HTTP Method HttpClient Purpose
Create POST http.post() Add new resource
Read GET http.get() Retrieve resource
Update PUT http.put() Update resource
Delete DELETE http.delete() Remove resource

Step 1: Create a Data Model

A TypeScript interface can describe the structure of the resource used by the CRUD operations.

course.model.ts
export interface Course {

    id: number;

    name: string;

    duration: string;

    fees: number;

}

Step 2: Create CRUD Service

course.service.ts
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
    ) {
    }

}

1. Create Operation

The Create operation adds a new record to the backend.

Angular commonly sends the new resource using an HTTP POST request.

Service Method
addCourse(course: Course) {

    return this.http.post<Course>(
        this.apiUrl,
        course
    );

}
Component
course: Course = {

    id: 0,

    name: 'Java Full Stack',

    duration: '6 Months',

    fees: 35000

};


addCourse() {

    this.courseService
        .addCourse(this.course)
        .subscribe({

            next: response => {

                console.log(
                    'Course created:',
                    response
                );

            },

            error: error => {

                console.error(error);

            }

        });

}

Create Operation Flow

Form User Enters Data
→
Component addCourse()
→
Service POST
→
API Creates Record

2. Read Operation

The Read operation retrieves existing records from the backend.

Angular commonly uses an HTTP GET request for this operation.

Service Method
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);

            }

        });

}

Courses Loaded

Java Full Stack

.NET Full Stack

Python Full Stack

Read a Single Record

Service Method
getCourse(id: number) {

    return this.http.get<Course>(
        this.apiUrl + '/' + id
    );

}
Component
loadCourse(id: number) {

    this.courseService
        .getCourse(id)
        .subscribe({

            next: course => {

                console.log(course);

            },

            error: error => {

                console.error(error);

            }

        });

}

3. Update Operation

The Update operation modifies an existing backend resource.

Angular can send the updated resource using an HTTP PUT request.

Service Method
updateCourse(
    id: number,
    course: Course
) {

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

}
Component
updateCourse(course: Course) {

    this.courseService
        .updateCourse(
            course.id,
            course
        )
        .subscribe({

            next: updatedCourse => {

                console.log(
                    'Updated:',
                    updatedCourse
                );

            },

            error: error => {

                console.error(error);

            }

        });

}

Update Operation Flow

Edit Form Modify Data
→
Component updateCourse()
→
Service PUT
→
API Updates Record

4. Delete Operation

The Delete operation removes an existing backend resource.

Angular can send the resource identifier through an HTTP DELETE request.

Service Method
deleteCourse(id: number) {

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

}
Component
deleteCourse(id: number) {

    this.courseService
        .deleteCourse(id)
        .subscribe({

            next: () => {

                console.log(
                    'Course deleted'
                );

            },

            error: error => {

                console.error(error);

            }

        });

}

Delete Operation Flow

Delete Button User Action
→
Component deleteCourse()
→
Service DELETE
→
API Removes Record

Complete CRUD Service

course.service.ts
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
    ) {
    }


    // CREATE

    addCourse(course: Course) {

        return this.http.post<Course>(
            this.apiUrl,
            course
        );

    }


    // READ

    getCourses() {

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

    }


    // READ SINGLE

    getCourse(id: number) {

        return this.http.get<Course>(
            this.apiUrl + '/' + id
        );

    }


    // UPDATE

    updateCourse(
        id: number,
        course: Course
    ) {

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

    }


    // DELETE

    deleteCourse(id: number) {

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

    }

}

Complete CRUD Architecture

Angular UI User Interaction
→
Component Calls Service
→
Service HttpClient
→
REST API Backend
→
Database Persistent Data

CRUD Component Example

courses.component.ts
export class CoursesComponent {

    courses: Course[] = [];

    loading = false;

    errorMessage = '';


    loadCourses() {

        this.loading = true;
        this.errorMessage = '';

        this.courseService
            .getCourses()
            .subscribe({

                next: courses => {

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

                },

                error: error => {

                    console.error(error);

                    this.errorMessage =
                        'Unable to load courses.';

                    this.loading = false;

                }

            });

    }


    addCourse(course: Course) {

        this.courseService
            .addCourse(course)
            .subscribe({

                next: createdCourse => {

                    this.courses = [
                        ...this.courses,
                        createdCourse
                    ];

                },

                error: error => {

                    console.error(error);

                }

            });

    }


    updateCourse(course: Course) {

        this.courseService
            .updateCourse(
                course.id,
                course
            )
            .subscribe({

                next: updatedCourse => {

                    this.courses =
                        this.courses.map(
                            item =>
                                item.id ===
                                updatedCourse.id
                                    ? updatedCourse
                                    : item
                        );

                },

                error: error => {

                    console.error(error);

                }

            });

    }


    deleteCourse(id: number) {

        this.courseService
            .deleteCourse(id)
            .subscribe({

                next: () => {

                    this.courses =
                        this.courses.filter(
                            course =>
                                course.id !== id
                        );

                },

                error: error => {

                    console.error(error);

                }

            });

    }

}

CRUD Template Example

courses.component.html
<button
    class="btn btn-primary"
    (click)="loadCourses()">

    Load Courses

</button>


@if (loading) {

    <p>
        Loading...
    </p>

}


@if (errorMessage) {

    <div class="alert alert-danger">

        {{ errorMessage }}

    </div>

}


@for (course of courses; track course.id) {

    <div class="course-card">

        <h3>
            {{ course.name }}
        </h3>

        <p>
            Duration:
            {{ course.duration }}
        </p>

        <p>
            Fees:
            ₹{{ course.fees }}
        </p>

        <button
            class="btn btn-outline-primary"
            (click)="updateCourse(course)">

            Edit

        </button>

        <button
            class="btn btn-outline-danger"
            (click)="deleteCourse(course.id)">

            Delete

        </button>

    </div>

}

CIIT Training Institute CRUD Example

Suppose the CIIT Training Institute has an admin dashboard where authorized staff can manage training course information.

The Angular frontend can use CRUD operations to create new courses, load existing courses, update course details and delete records through the backend API.

Create Course
const newCourse: Course = {

    id: 0,

    name: '.NET Full Stack',

    duration: '6 Months',

    fees: 35000

};


this.courseService
    .addCourse(newCourse)
    .subscribe({

        next: course => {

            console.log(
                'Created:',
                course
            );

        }

    });
Read Courses
this.courseService
    .getCourses()
    .subscribe({

        next: courses => {

            this.courses = courses;

        }

    });
Update Course
const updatedCourse:
    Course = {

        id: 101,

        name: 'Java Full Stack',

        duration: '8 Months',

        fees: 40000

    };


this.courseService
    .updateCourse(
        updatedCourse.id,
        updatedCourse
    )
    .subscribe({

        next: course => {

            console.log(
                'Updated:',
                course
            );

        }

    });
Delete Course
this.courseService
    .deleteCourse(101)
    .subscribe({

        next: () => {

            console.log(
                'Course deleted'
            );

        }

    });

CIIT Training Institute Admin

Create: Add new training course

Read: View available courses

Update: Modify course details

Delete: Remove a course record

CRUD Operation States

L
Loading

Indicates that an API operation is currently running.

S
Success

The requested CRUD operation completed successfully.

E
Error

The application handles a failed API operation.

R
Refresh

The UI can reflect the latest backend data after changes.

Complete CRUD Reference

Operation Method Example Endpoint Angular Method
Create POST /api/courses http.post()
Read All GET /api/courses http.get()
Read One GET /api/courses/101 http.get()
Update PUT /api/courses/101 http.put()
Delete DELETE /api/courses/101 http.delete()

CRUD Integration Best Practices

  • Keep CRUD API calls inside dedicated Angular services.
  • Use TypeScript interfaces or types for request and response data.
  • Handle loading, success and error states appropriately.
  • Update the UI after successful create, update or delete operations.
  • Keep API endpoints centralized instead of duplicating URLs.
  • Validate user input before sending create or update requests.

Important Points

1. Create Uses POST

POST is commonly used to send a new resource to the API.

2. Read Uses GET

GET retrieves existing resources from the backend.

3. Update Uses PUT

PUT can send updated information for an existing resource.

4. Delete Uses DELETE

DELETE requests remove a resource identified by its API endpoint.

Summary

CRUD represents Create, Read, Update and Delete operations commonly required for managing application data.

Angular can implement CRUD through a service using HttpClient and the HTTP methods POST, GET, PUT and DELETE.

A typical flow is Angular UI → Component → Service → HttpClient → REST API → Database . In the next topic, we will learn how to handle API Responses properly.