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 Navigation

Learn how to navigate between Angular routes using routerLink, Router, navigate() and navigateByUrl().

What is Navigation?

In Angular, navigation means moving from one route or application view to another without reloading the complete web page.

Angular provides routing features that allow users to open different views such as courses, dashboard, contact and enquiry pages.

Navigation can be performed directly from the template using routerLink or programmatically using the Angular Router service.

Angular Navigation Flow

User Action Click Link / Button
→
Router Checks Route
→
Route Matches Path
→
Component Displayed

Common Navigation Methods

1
routerLink

Used to navigate directly from an HTML template.

2
navigate()

Used for programmatic navigation using route segments.

3
navigateByUrl()

Navigates using a complete URL string.

4
Query Parameters

Additional values can be passed through the URL.

Using routerLink

routerLink is the simplest way to navigate between Angular routes from an HTML template.

Instead of manually changing the browser URL, Angular Router handles the navigation.

Template Example
<a routerLink="/courses">
    Courses
</a>

<a routerLink="/contact">
    Contact
</a>

CIIT Training Institute Example

Navigation Menu
<nav>

    <a routerLink="/home">
        Home
    </a>

    <a routerLink="/courses">
        Courses
    </a>

    <a routerLink="/enquiry">
        Enquiry
    </a>

    <a routerLink="/contact">
        Contact
    </a>

</nav>

CIIT Training Institute

Home → Courses → Enquiry → Contact

Users can move between different application views without refreshing the complete page.

Programmatic Navigation

Sometimes navigation needs to happen after a button click, form submission or another operation.

In such cases Angular's Router service can be used to navigate programmatically.

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

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

    constructor(private router: Router) {
    }

    openCourses() {
        this.router.navigate(['/courses']);
    }

}
HTML Button
<button
    type="button"
    (click)="openCourses()">

    View Courses

</button>

Using navigate()

The navigate() method accepts route segments in the form of an array.

It is useful when the destination route is built dynamically.

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

this.router.navigate(['/contact']);
Dynamic Navigation
openCourse(courseId: number) {

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

}

Using navigateByUrl()

The navigateByUrl() method navigates using a complete URL string.

This can be useful when the complete destination URL is already known.

Example
this.router.navigateByUrl('/courses');

this.router.navigateByUrl('/contact');

Navigation with Query Parameters

Query parameters allow additional information to be included in the URL.

For example, a course page can receive a category or filter value through the query string.

routerLink with Query Parameters
<a
    [routerLink]="['/courses']"
    [queryParams]="{
        category: 'dotnet'
    }">

    View .NET Courses

</a>
Programmatic Navigation
this.router.navigate(
    ['/courses'],
    {
        queryParams: {
            category: 'dotnet'
        }
    }
);

Relative Navigation

Relative navigation is used when navigation should happen from the current route instead of starting from the application root.

This is useful with nested or child routes.

Example
this.router.navigate(
    ['details'],
    {
        relativeTo: this.route
    }
);

routerLink vs navigate() vs navigateByUrl()

Method Used From Purpose
routerLink HTML Template Navigate when the user clicks a link or element.
navigate() Component / TypeScript Programmatic navigation using route segments.
navigateByUrl() Component / TypeScript Navigate using a complete URL.
queryParams Template / TypeScript Pass additional values through the URL.

Complete Navigation Example

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

@Component({
    selector: 'app-dashboard',
    templateUrl: './dashboard.component.html'
})
export class DashboardComponent {

    constructor(private router: Router) {
    }

    openCourses() {

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

    }

    openContact() {

        this.router.navigateByUrl('/contact');

    }

}
Template
<div class="dashboard">

    <h2>
        CIIT Training Institute Dashboard
    </h2>

    <a routerLink="/courses">
        Courses
    </a>

    <button
        type="button"
        (click)="openCourses()">

        Open Courses

    </button>

    <button
        type="button"
        (click)="openContact()">

        Contact Institute

    </button>

</div>

Important Points

1. Use routerLink for Template Navigation

Use routerLink when navigation is directly triggered from an HTML template.

2. Use Router for Programmatic Navigation

Use the Angular Router service when navigation needs to happen from TypeScript code.

3. Use navigate() for Route Segments

navigate() accepts route segments and is useful for dynamic routes.

4. Keep Navigation Clear

Use meaningful routes and avoid unnecessary navigation logic inside components.

Navigation Best Practices

  • Use routerLink for normal template-based navigation.
  • Use navigate() when navigation depends on application logic.
  • Use navigateByUrl() when the complete URL is already available.
  • Use query parameters only when additional URL information is required.
  • Keep route paths meaningful and consistent.
  • Avoid unnecessary full-page reloads in Angular applications.

Summary

Angular navigation allows users to move between different application views without reloading the complete page.

routerLink is commonly used inside templates, while the Angular Router service provides programmatic navigation through methods such as navigate() and navigateByUrl().

In the next topic, we will learn how to work with Route Parameters.