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 Child Routes

Learn how to create nested routes in Angular using children and display child components with router-outlet.

What are Child Routes?

Child routes are routes defined inside another route. They are also called nested routes.

They are useful when one main page contains multiple related sections or views.

For example, a course dashboard can contain child pages such as Overview, Topics and Assignments.

Child Route Flow

Parent Route /courses
→
Child Route overview
→
Router Outlet Displays Child
→
Child Component OverviewComponent

Important Concepts

1
Parent Route

The main route that contains one or more child routes.

2
Children

The children property defines nested routes.

3
router-outlet

It provides the location where the child component is displayed.

4
Nested URL

A child route becomes part of the parent route URL.

Defining Child Routes

Angular allows child routes to be defined using the children property of a route.

Each child route contains its own path and component.

Route Configuration
const routes: Routes = [

    {
        path: 'courses',
        component: CoursesComponent,

        children: [
            {
                path: 'overview',
                component: OverviewComponent
            },
            {
                path: 'topics',
                component: TopicsComponent
            }
        ]
    }

];

Nested URL Structure

Example URLs
/courses/overview

/courses/topics

Route Structure

Parent Route: /courses

Child Route: /overview

Complete URL: /courses/overview

Using router-outlet

The parent component needs a router-outlet where Angular can display the selected child component.

Without the outlet, the child route has no location in the parent template where it can be rendered.

Parent Component HTML
<h2>
    CIIT Training Institute Courses
</h2>

<nav>

    <a routerLink="overview">
        Overview
    </a>

    <a routerLink="topics">
        Topics
    </a>

</nav>

<router-outlet></router-outlet>

Parent and Child Relationship

CoursesComponent Parent
→
router-outlet Child Location
→
OverviewComponent Child

Navigating to Child Routes

Child routes can be accessed from the parent component using relative route links.

The child path is written without repeating the complete parent URL.

Template Navigation
<a routerLink="overview">
    Course Overview
</a>

<a routerLink="topics">
    Course Topics
</a>

Programmatic Child Navigation

Child routes can also be opened programmatically using the Angular Router.

Relative navigation is useful when the current component is already inside the parent route.

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

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

    constructor(
        private router: Router,
        private route: ActivatedRoute
    ) {
    }

    openTopics() {

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

    }

}
Button
<button
    type="button"
    (click)="openTopics()">

    View Topics

</button>

CIIT Training Institute Example

Course Routes
const routes: Routes = [

    {
        path: 'courses',
        component: CoursesComponent,

        children: [
            {
                path: 'overview',
                component: CourseOverviewComponent
            },
            {
                path: 'topics',
                component: CourseTopicsComponent
            },
            {
                path: 'contact',
                component: CourseContactComponent
            }
        ]
    }

];
Parent Template
<h2>
    CIIT Training Institute
</h2>

<nav>

    <a routerLink="overview">
        Course Overview
    </a>

    <a routerLink="topics">
        Course Topics
    </a>

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

</nav>

<router-outlet></router-outlet>

CIIT Training Institute

/courses/overview → Course Overview

/courses/topics → Course Topics

/courses/contact → Course Contact

Nested Child Routes

Child routes can themselves contain additional child routes.

This creates multiple levels of routing when an application has a more complex structure.

Example
const routes: Routes = [

    {
        path: 'courses',
        component: CoursesComponent,

        children: [
            {
                path: 'fullstack',
                component: FullStackComponent,

                children: [
                    {
                        path: 'topics',
                        component: TopicsComponent
                    }
                ]
            }
        ]
    }

];

Parent Routes vs Child Routes

Feature Parent Route Child Route
Location Top-level route Inside a parent route
Configuration Defined directly in routes Defined inside children
URL Example /courses /courses/topics
Rendering Application outlet Parent's router-outlet

Important Points

1. Use children Property

Define nested routes using the children property.

2. Add router-outlet

The parent component should contain router-outlet for displaying child views.

3. Keep Related Pages Together

Child routes are useful for grouping pages that belong to the same parent feature.

4. Use Relative Navigation

Relative links and navigation can make nested route navigation easier to maintain.

Child Route Best Practices

  • Use child routes for logically related pages.
  • Keep route hierarchy simple and meaningful.
  • Place router-outlet in the parent component where child content should appear.
  • Use relative navigation when working inside nested routes.
  • Avoid creating unnecessary levels of nested routes.
  • Use clear and descriptive child route names.

Summary

Angular child routes allow an application to create nested navigation structures.

The children property defines nested routes, while router-outlet provides the location where the child component is rendered.

Child routes are useful for organizing related sections such as course overview, topics and contact pages. In the next topic, we will learn about Route Guards.