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 Configuration

Angular Route Configuration defines the URL paths of an application and specifies which component should be displayed when a particular route is activated.

What is Route Configuration?

Route configuration is the process of defining Angular routes using a Routes array.

Each route can contain a path and a component. Angular uses this configuration to determine which component should be displayed for the current URL.

Simple Definition

Route Configuration connects a URL path with an Angular component.

Route Configuration Flow

URL Path /courses
→
Route Matches Path
→
Component Selected View
→
RouterOutlet Displays View

1. Creating a Routes Array

Angular routes are commonly stored in a Routes 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 /courses, Angular matches the route and displays CoursesComponent.

2. Understanding a Route Object

A route is represented by an object containing configuration properties such as path and component.

Route Object
{

    path: 'courses',

    component: CoursesComponent

}
path

Defines the URL segment used for the route.

'courses'
component

Defines the component displayed by the route.

CoursesComponent
children

Defines nested child routes.

children
canActivate

Defines route activation guards.

canActivate

3. Configuring Multiple Routes

An Angular application can contain multiple routes for different components.

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

    {
        path: '',
        component: HomeComponent
    },

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

    {
        path: 'contact',
        component: ContactComponent
    }

];
Configured Routes:

/ → HomeComponent

/courses → CoursesComponent

/contact → ContactComponent

4. Configuring the Default Route

An empty path can represent the default route of an application.

Default Route
{

    path: '',

    component: HomeComponent

}
Meaning

The empty path represents the root URL of the application.

5. Redirecting a Route

A route can redirect the user from one path to another path using redirectTo.

Example
export const routes: Routes = [

    {

        path: '',

        redirectTo: 'home',

        pathMatch: 'full'

    },

    {

        path: 'home',

        component: HomeComponent

    }

];
Root URL /
→
redirectTo home
→
HomeComponent Displays Home

6. Configuring a Wildcard Route

A wildcard route can handle URLs that do not match another configured route.

Example
export const routes: Routes = [

    {

        path: 'courses',

        component: CoursesComponent

    },

    {

        path: '**',

        component: NotFoundComponent

    }

];
Example:
Unknown URL → NotFoundComponent

7. Parameterized Route Configuration

Route parameters allow part of the URL to contain dynamic data.

Example
{

    path: 'course/:id',

    component: CourseDetailsComponent

}
Example URL
/course/101
Meaning

The :id segment represents dynamic route information.

8. Configuring Child Routes

Child routes can be defined inside a parent route using the children property.

Example
export const routes: Routes = [

    {

        path: 'courses',

        component: CoursesComponent,

        children: [

            {

                path: 'details',

                component:
                    CourseDetailsComponent

            }

        ]

    }

];
Parent /courses
→
Child /details
→
Nested View Course Details

9. Configuring Route Guards

A route can use guards to control whether navigation to a route should be allowed.

Example
{

    path: 'admin',

    component: AdminComponent,

    canActivate: [
        authGuard
    ]

}
Use Case

Guards are commonly used to protect application areas that require authentication or other conditions.

10. Lazy Loading Route Configuration

Routes can also be configured to load feature components or route configurations only when they are needed.

Example
{

    path: 'admin',

    loadComponent: () =>
        import('./admin.component')
            .then(m => m.AdminComponent)

}
Benefit

Lazy loading can keep larger applications modular by loading feature code when that route is needed.

11. Common Route Configuration Patterns

Default Route

Defines the root application page.

path: ''
Static Route

Uses a fixed path such as courses.

path: 'courses'
Dynamic Route

Uses a parameter in the route path.

path: 'course/:id'
Wildcard Route

Handles unmatched URLs.

path: '**'

12. Connecting Routes with RouterOutlet

The configured component needs a router-outlet placeholder where Angular can render the routed view.

app.component.html
<nav>

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

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

</nav>

<router-outlet>
</router-outlet>
Important

The router-outlet is the location where Angular renders the component associated with the active route.

Route Configuration Quick Reference

Property Purpose Example
path Defines the URL path. path: 'courses'
component Defines the component displayed by the route. component: CoursesComponent
redirectTo Redirects one route to another. redirectTo: 'home'
children Defines nested routes. children: []
canActivate Controls route activation. canActivate: [authGuard]
loadComponent Loads a component dynamically. loadComponent: () => import(...)

Complete CIIT Training Institute Example

Suppose the CIIT Training Institute Angular application has Home, Courses, Course Details and Contact pages. We can define routes for each page and use RouterOutlet to display them.

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: 'contact',

        component: ContactComponent

    },

    {

        path: '**',

        component: NotFoundComponent

    }

];
app.component.html
<nav>

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

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

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

</nav>

<router-outlet>
</router-outlet>
Configured CIIT Routes:

/ → CIIT Home

/courses → Course List

/course/101 → Course Details

/contact → Contact Page

Important Points About Route Configuration

  • Routes are defined using a Routes array.
  • The path defines the URL segment.
  • The component property identifies the component displayed for the route.
  • redirectTo can redirect one path to another.
  • children can be used for nested routes.
  • Wildcard routes can handle unmatched URLs.

Route Configuration Best Practices

  • Keep route paths meaningful and easy to understand.
  • Use consistent naming for related routes.
  • Keep wildcard handling at the appropriate place in the route configuration.
  • Use child routes when a feature contains logically nested views.
  • Use route guards for protected application areas.
  • Keep large applications organized into clear routing structures.

Summary

Angular Route Configuration defines the relationship between application URLs and Angular components.

Important configuration properties include path, component, redirectTo, children, canActivate, and loadComponent.