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

RxJS Combining Observables

Learn how RxJS can combine multiple Observable streams and produce useful results from different data sources.

What is Combining Observables?

In real applications, data often comes from more than one Observable source.

RxJS provides combination operators that allow multiple Observables to work together and produce a new Observable.

Common combination operators include combineLatest(), forkJoin(), merge() and concat().

Combining Observable Flow

Observable A First Data Source
+
Observable B Second Data Source
→
Combination Operator Combines Streams
→
Result New Observable

Why Combine Observables?

D
Multiple Data Sources

Work with data coming from different Observables.

C
Coordinated Data

Produce results based on multiple streams.

A
API Coordination

Coordinate multiple asynchronous API operations.

U
Unified Result

Create one stream from multiple related sources.

combineLatest()

combineLatest() combines the latest values emitted by multiple Observables.

After each source has emitted at least one value, a new combined value can be emitted whenever any source emits again.

Example
const course$ = of(
    'Java',
    '.NET'
);

const mode$ = of(
    'Online',
    'Offline'
);

const result$ =
    combineLatest([
        course$,
        mode$
    ]);

result$.subscribe({

    next: result => {

        console.log(result);

    }

});

Combined Result

Course: Java

Mode: Online

Result is represented as a combined value.

combineLatest() Flow

Course Java
+
Mode Online
→
Latest Combination [Java, Online]

forkJoin()

forkJoin() is useful when multiple Observables need to complete and the application wants their final emitted values together.

It is commonly useful for coordinating multiple finite asynchronous operations such as independent API requests.

Example
const courses$ =
    this.courseService.getCourses();

const trainers$ =
    this.trainerService.getTrainers();

forkJoin({

    courses: courses$,

    trainers: trainers$

}).subscribe({

    next: result => {

        console.log(
            result.courses
        );

        console.log(
            result.trainers
        );

    },

    error: error => {

        console.error(error);

    }

});

forkJoin() Flow

Courses API Complete
+
Trainers API Complete
→
forkJoin() Final Values
→
Dashboard Combined Data

merge()

merge() combines multiple Observables into one Observable by forwarding their emissions into the resulting stream.

Values are emitted as the source Observables produce them, so the resulting order depends on the timing of emissions.

Example
const java$ = of(
    'Java'
);

const dotnet$ = of(
    '.NET'
);

const merged$ =
    merge(
        java$,
        dotnet$
    );

merged$.subscribe({

    next: course => {

        console.log(course);

    }

});

Output

Java

.NET

concat()

concat() subscribes to Observables in sequence.

The next Observable starts after the previous Observable completes.

Example
const first$ = of(
    'Introduction',
    'Components'
);

const second$ = of(
    'Services',
    'Routing'
);

const topics$ =
    concat(
        first$,
        second$
    );

topics$.subscribe({

    next: topic => {

        console.log(topic);

    }

});

Output Order

Introduction

Components

Services

Routing

Combining Operators Comparison

Operator Main Purpose Behavior
combineLatest() Combine latest values Emits when source values change after all sources have emitted
forkJoin() Combine final values Emits when all source Observables complete
merge() Merge emissions Forwards values as they are emitted
concat() Sequential combination Subscribes to the next source after the previous one completes

When to Use combineLatest()

F
Form Values

Combine the latest values from multiple form-related streams.

S
Search Filters

Combine values from different filter controls.

D
Dashboard Data

Work with the latest values from related streams.

R
Reactive UI

React to changes in multiple Observable sources.

When to Use forkJoin()

A
Multiple APIs

Wait for several finite API operations to complete.

R
Reports

Collect final results from several independent requests.

D
Initial Data

Load multiple independent datasets before continuing.

F
Final Results

Use when only the final values are required.

CIIT Training Institute Example

Suppose the CIIT Training Institute dashboard needs three independent pieces of information: courses, trainers and enquiries.

The dashboard can coordinate these Observables and prepare a combined result for display.

Dashboard Data
const courses$ =
    courseService.getCourses();

const trainers$ =
    trainerService.getTrainers();

const enquiries$ =
    enquiryService.getEnquiries();

forkJoin({

    courses: courses$,

    trainers: trainers$,

    enquiries: enquiries$

}).subscribe({

    next: dashboard => {

        console.log(
            dashboard
        );

    },

    error: error => {

        console.error(
            error
        );

    }

});

CIIT Training Institute Dashboard

Courses: Loaded

Trainers: Loaded

Enquiries: Loaded

Dashboard data is ready after the required streams complete.

Choosing the Right Combination Strategy

Latest Values combineLatest()
|
Final Values forkJoin()
|
Concurrent Emissions merge()
|
Sequential concat()

Combining and Transforming

Combination operators can also be followed by other RxJS operators.

This allows the application to combine streams first and then transform or filter the combined result.

Example
const course$ = of(
    'Java'
);

const mode$ = of(
    'Online'
);

const result$ =
    combineLatest([
        course$,
        mode$
    ]).pipe(

        map(([course, mode]) => {

            return course +
                ' - ' +
                mode;

        })

    );

result$.subscribe({

    next: result => {

        console.log(result);

    }

});

Output

Java - Online

Important Points

1. Combination Creates a New Observable

Combination operators produce an Observable based on multiple source Observables.

2. Choose Based on Stream Behavior

combineLatest(), forkJoin(), merge() and concat() have different timing and completion behavior.

3. Completion Matters

Some combination strategies depend on source Observables completing before producing their final result.

4. Combination Can Be Followed by Other Operators

A combined stream can be transformed or filtered using additional RxJS operators.

Combining Observable Best Practices

  • Choose the combination operator according to the required emission and completion behavior.
  • Use combineLatest() when the latest values from multiple sources are required.
  • Use forkJoin() when final values from finite sources are required after completion.
  • Use merge() when source emissions should flow into one stream.
  • Use concat() when sources should be processed sequentially.
  • Keep combined stream logic readable and avoid unnecessary combinations.

Summary

RxJS provides several operators for combining multiple Observable streams.

combineLatest() works with the latest values, forkJoin() works with final values after completion, merge() combines emissions, and concat() processes sources sequentially.

In the next topic, we will learn about Higher Order Mapping.