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 Routing

Angular Routing allows an application to display different components based on the current URL. It helps build multi-page-like navigation experiences inside a single-page Angular application.

What is Angular Routing?

Angular Routing is the mechanism used to navigate between different views or components in an Angular application.

Instead of loading a completely new web page for every URL, Angular changes the displayed component while keeping the application running.

Simple Definition

Angular Routing connects URLs with Angular components and controls which component should be displayed for a particular route.

Angular Routing Flow

URL User navigates
→
Router Matches route
→
Route Selects component
→
Component Displays view

Main Angular Routing Concepts

Routes

Define the URL path and the component associated with it.

path: 'courses'
Router

Performs navigation between routes.

Router
RouterLink

Creates navigation links inside Angular templates.

routerLink
RouterOutlet

Displays the component associated with the current route.

router-outlet

1. Basic Route Configuration

Angular routes are defined using a route configuration array.

app.routes.ts
import { Routes } from '@angular/router';

export const routes: Routes = [

    {
        path: 'courses',
        component: CoursesComponent
    }

];
How it works

When the user navigates to the /courses URL, Angular can display the CoursesComponent.

2. Router Outlet

The router-outlet directive acts as a placeholder where Angular renders the component matched by the current route.

app.component.html
<nav>

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

</nav>

<router-outlet>
</router-outlet>
URL /courses
→
Router Matches Route
→
RouterOutlet Displays Component

3. RouterLink Navigation

The routerLink directive is commonly used to navigate between routes from an Angular template.

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

<a routerLink="/contact">
    Contact
</a>
Navigation Example:

4. Programmatic Navigation

The Angular Router can be used when navigation needs to happen from component code.

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(): void {

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

    }

}
Template
<button
    class="btn btn-primary"
    (click)="openCourses()">

    Open Courses

</button>
Use Case

Programmatic navigation is useful when navigation should happen after an operation such as login, form submission, or saving data.

5. Common Route Types

Root Route

Represents the default application route.

path: ''
Static Route

Uses a fixed URL path.

path: 'courses'
Parameterized Route

Includes a dynamic route parameter.

path: 'course/:id'
Child Route

Defines routes inside another route.

children

6. Default Route

An empty path can be configured as the default route for an application.

app.routes.ts
export const routes: Routes = [

    {
        path: '',
        component: HomeComponent
    }

];
Meaning

When the application is opened without another route path, Angular can display the HomeComponent.

7. Wildcard Route

A wildcard route can be used to handle URLs that do not match any configured route.

app.routes.ts
export const routes: Routes = [

    {
        path: 'courses',
        component: CoursesComponent
    },

    {
        path: '**',
        component: NotFoundComponent
    }

];
Example:

Unknown URL → Not Found Page

8. Route Matching

Angular evaluates the configured routes and selects the route that matches the current URL according to the router configuration.

Example
export const routes: Routes = [

    {
        path: 'courses',
        component: CoursesComponent
    },

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

    {
        path: '**',
        component: NotFoundComponent
    }

];
Important

Keep route configuration organized so that specific application routes are defined before a catch-all wildcard route.

9. Route Parameters Preview

Angular routes can contain dynamic parameters when a component needs to display information based on an identifier.

Route
{
    path: 'course/:id',
    component: CourseDetailsComponent
}
Example URL
/course/101
What is Next?

Route parameters are covered in detail in the Route Parameters topic.

10. Child Routes Preview

Child routes allow a feature area to contain routes nested under a parent route.

Example
{

    path: 'courses',

    component: CoursesComponent,

    children: [

        {
            path: 'details',
            component: CourseDetailsComponent
        }

    ]

}
Parent Route /courses
→
Child Route /details
→
Nested View Course Details

11. Route Guards Preview

Route guards can control whether navigation to a route should be allowed based on application conditions.

Example
{

    path: 'admin',

    component: AdminComponent,

    canActivate: [
        authGuard
    ]

}
Use Case

Route guards are commonly used for protected areas such as dashboards, admin pages, and authenticated features.

12. Navigation Methods

routerLink

Navigate directly from an Angular template.

routerLink="/courses"
navigate()

Navigate programmatically using route segments.

router.navigate()
navigateByUrl()

Navigate using a URL string.

navigateByUrl()
Back Navigation

Application logic can navigate back when required.

Location

Complete CIIT Training Institute Routing Example

Suppose CIIT Training Institute has separate pages for the home page, course list, and course details. Angular Routing can connect these views with clean URLs.

app.routes.ts
import { Routes } from '@angular/router';

export const routes: Routes = [

    {
        path: '',
        component: HomeComponent
    },

    {
        path: 'courses',
        component: CoursesComponent
    },

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

    {
        path: '**',
        component: NotFoundComponent
    }

];
app.component.html
<nav>

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

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

</nav>

<router-outlet>
</router-outlet>
course-details.component.ts
import {
    Component,
    OnInit
} from '@angular/core';

import { ActivatedRoute }
from '@angular/router';

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

    courseId = '';

    constructor(
        private route: ActivatedRoute
    ) {

    }

    ngOnInit(): void {

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

    }

}
Example URLs:

Home: /

Courses: /courses

Course Details: /course/101

Example Course: Java Full Stack

Angular Routing Quick Reference

Concept Purpose Example
Route Maps URL path to component path: 'courses'
routerLink Template navigation routerLink="/courses"
Router Programmatic navigation router.navigate()
RouterOutlet Displays routed component <router-outlet>
Route Parameter Pass dynamic URL information :id
Child Route Create nested routes children
Route Guard Control route access canActivate

Important Points About Angular Routing

  • Routes connect URL paths with Angular components.
  • RouterLink is commonly used for template navigation.
  • Router can be used for programmatic navigation.
  • RouterOutlet displays the currently matched component.
  • Route parameters allow dynamic information to be represented in a URL.
  • Child routes and route guards support larger application navigation structures.

Angular Routing Best Practices

  • Keep route paths meaningful and easy to understand.
  • Use consistent route naming throughout the application.
  • Use routerLink for normal template navigation.
  • Use programmatic navigation when navigation depends on application logic.
  • Organize child routes logically for larger features.
  • Use route guards for protected application areas when required.

Summary

Angular Routing connects URLs with components and allows users to navigate between different views inside an Angular application.

Important routing features include Routes, Router, RouterLink, RouterOutlet, Route Parameters, Child Routes and Route Guards.