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

Custom Pipes

Learn how to create reusable Angular Pipes for custom data transformation and formatting requirements.

What are Custom Pipes?

Custom Pipes are developer-created Pipes used when the built-in Angular Pipes do not provide the required transformation.

They allow reusable formatting or transformation logic to be used directly inside Angular templates.

Custom Pipe Flow

1
Input Data

Component provides the original value.

→
2
Custom Pipe

The Pipe receives the value.

→
3
Transform

The custom transformation is performed.

→
4
Output

The transformed value is displayed.

Why Use Custom Pipes?

R
Reusable

Use the same transformation in multiple templates.

C
Clean Templates

Keep transformation logic outside complex template expressions.

F
Flexible

Create formatting rules specific to your application.

M
Maintainable

Keep reusable transformation logic in one place.

Creating a Custom Pipe

Angular CLI can generate a custom Pipe automatically.

CLI Command
ng generate pipe studentName

Short form:

CLI
ng g pipe studentName

Custom Pipe Structure

student-name.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: 'studentName'
})
export class StudentNamePipe implements PipeTransform {

    transform(value: string): string {
        return value;
    }

}
Explanation:
The @Pipe decorator defines the Pipe and PipeTransform provides the transformation method.

The transform() Method

The transform() method receives the input value and returns the transformed result.

Example
transform(value: string): string {
    return value.toUpperCase();
}
Result:
The input text is converted to uppercase.

Complete Custom Pipe Example

student-name.pipe.ts
import {
    Pipe,
    PipeTransform
} from '@angular/core';

@Pipe({
    name: 'studentName'
})
export class StudentNamePipe implements PipeTransform {

    transform(value: string): string {
        return value.toUpperCase();
    }

}
student.component.ts
studentName = 'Samiksha';
student.component.html
<p>
    {{studentName | studentName}}
</p>
Output:
SAMIKSHA

Custom Pipe with Parameter

Custom Pipes can also accept parameters to make the transformation configurable.

Pipe
transform(
    value: string,
    prefix: string
): string {

    return prefix + value;

}
Template
<p>
    {{studentName | studentName:'Student: '}}
</p>
Output:
Student: Samiksha

Using a Custom Pipe with Multiple Students

Component
student1 = 'Sam';
student2 = 'Pradnya';
student3 = 'Samiksha';
Template
<p>
    {{student1 | studentName}}
</p>

<p>
    {{student2 | studentName}}
</p>

<p>
    {{student3 | studentName}}
</p>

SAM

PRADNYA

SAMIKSHA

Built-in Pipe vs Custom Pipe

Built-in Pipe Custom Pipe
Provided by Angular Created by developer
Ready to use Created for specific requirements
Examples: date, currency, uppercase Example: studentName
General-purpose transformations Application-specific transformations

Common Custom Pipe Use Cases

N
Name Formatting

Format student or employee names consistently.

F
Custom Formatting

Create application-specific display formats.

T
Text Transformation

Transform text according to application requirements.

R
Reusable Logic

Reuse the same transformation in multiple views.

Custom Pipe Transformation Flow

Samiksha Original Value
→
studentName Custom Pipe
→
SAMIKSHA Transformed Value

Best Practices

  • Create a custom Pipe only when built-in Pipes are not sufficient.
  • Keep the transformation logic simple and focused.
  • Use meaningful Pipe names.
  • Keep reusable formatting logic inside the Pipe.
  • Use parameters when the transformation needs customization.
  • Avoid placing complex business logic inside Pipes.
  • Keep Pipes focused on presentation and transformation.

Summary

  • Custom Pipes are created for application-specific transformations.
  • The @Pipe decorator defines a custom Pipe.
  • PipeTransform provides the transform() method.
  • The transform() method receives and transforms data.
  • Custom Pipes can accept parameters.
  • Custom Pipes make reusable transformation logic easier to maintain.
  • Use built-in Pipes whenever they already satisfy the requirement.