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 Route Parameters

Learn how to pass dynamic values through Angular routes and retrieve them inside components using ActivatedRoute.

What are Route Parameters?

Route parameters are dynamic values that can be included inside a route URL.

They are commonly used when the application needs to open a specific record, course, product or other resource.

For example, a route such as /courses/101 can use 101 as a course identifier.

Route Parameter Flow

Route /courses/:id
→
URL /courses/101
→
ActivatedRoute Reads id
→
Component Uses value

Important Concepts

1
Dynamic Segment

A route can contain a dynamic segment such as :id.

2
Route URL

The actual URL contains the value for the dynamic segment.

3
ActivatedRoute

Angular provides ActivatedRoute to access route information.

4
Parameter Value

The component can use the received value in its logic.

Defining a Route Parameter

A dynamic route parameter is defined using a colon followed by the parameter name.

In the following example, :id represents a dynamic route parameter.

Route Configuration
const routes: Routes = [

    {
        path: 'courses/:id',
        component: CourseDetailsComponent
    }

];

Example URL

Dynamic URLs
/courses/101

/courses/205

/courses/501

Route Parameter Example

Route: /courses/:id

Current URL: /courses/101

Parameter value: 101

Passing Parameter using routerLink

Route parameters can be passed from an Angular template using routerLink.

The parameter value is placed after the route path.

Template Example
<a
    [routerLink]="['/courses', 101]">

    View Course

</a>
Another Example
<a
    [routerLink]="['/courses', course.id]">

    View Course Details

</a>

Reading Route Parameters

Angular provides the ActivatedRoute service to read parameters from the current route.

The parameter can be accessed through paramMap.

Component Example
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

@Component({
    selector: 'app-course-details',
    templateUrl: './course-details.component.html'
})
export class CourseDetailsComponent {

    courseId = '';

    constructor(
        private route: ActivatedRoute
    ) {
    }

    ngOnInit() {

        this.courseId =
            this.route.snapshot.paramMap.get('id') ?? '';

    }

}

Using snapshot

The snapshot property provides the current route information at the time the component is created.

It can be used when the component does not need to react to future changes of the same route parameter.

Example
const id =
    this.route.snapshot.paramMap.get('id');

Using paramMap

paramMap provides access to route parameters using their parameter names.

For example, the id parameter can be accessed using get('id').

Example
const courseId =
    this.route.snapshot.paramMap.get('id');

console.log(courseId);

CIIT Training Institute Example

Course Route
const routes: Routes = [

    {
        path: 'course/:id',
        component: CourseDetailsComponent
    }

];
Course Navigation
<a
    [routerLink]="['/course', 25]">

    .NET Full Stack

</a>

<a
    [routerLink]="['/course', 30]">

    Java Full Stack

</a>
Reading Course ID
courseId = '';

constructor(
    private route: ActivatedRoute
) {
}

ngOnInit() {

    this.courseId =
        this.route.snapshot.paramMap.get('id') ?? '';

}

CIIT Training Institute

Selected Course ID: 25

The same component can display different course details based on the route parameter.

Multiple Route Parameters

A route can contain more than one dynamic parameter.

Each parameter is defined using its own :parameterName syntax.

Route Configuration
const routes: Routes = [

    {
        path: 'course/:courseId/topic/:topicId',
        component: TopicComponent
    }

];
Example URL
/course/25/topic/4
Reading Parameters
const courseId =
    this.route.snapshot.paramMap.get('courseId');

const topicId =
    this.route.snapshot.paramMap.get('topicId');

Passing Parameters using navigate()

Parameters can also be supplied when performing programmatic navigation with navigate().

The parameter value is added as another route segment.

Example
openCourse(courseId: number) {

    this.router.navigate([
        '/courses',
        courseId
    ]);

}

Route Parameter vs Query Parameter

Feature Route Parameter Query Parameter
Example /courses/101 /courses?id=101
Definition Defined inside route path Passed after ?
Typical Use Identify a specific resource Filtering, sorting or optional information
Angular Access paramMap queryParamMap

Important Points

1. Use :parameterName

A dynamic route parameter is defined using a colon, such as :id.

2. Use ActivatedRoute

Use ActivatedRoute to access values from the current route.

3. Use Meaningful Parameter Names

Names such as courseId and topicId make the route easier to understand.

4. Keep Route Structure Clear

Use a meaningful URL structure when designing dynamic routes.

Route Parameter Best Practices

  • Use descriptive names for route parameters.
  • Use route parameters when a value identifies a specific resource.
  • Use ActivatedRoute to access current route information.
  • Keep dynamic route structures simple and meaningful.
  • Use query parameters for optional filtering or additional values.
  • Validate route values before using them in application logic.

Summary

Angular route parameters allow dynamic values to be included in application URLs.

A parameter such as :id is defined in the route, while ActivatedRoute can be used to read the value inside the component.

Route parameters are especially useful when opening specific course, topic or resource details. In the next topic, we will learn about Child Routes.