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 Form Submission

Learn how to submit Angular forms, validate the data, access form values and process submitted information using template-driven and reactive forms.

What is Form Submission?

Form submission is the process of collecting the values entered by the user and processing them after the form is submitted.

Angular provides different ways to handle form submission depending on whether the application uses template-driven or reactive forms.

Before processing the form, the application should check whether the submitted data satisfies the required validation rules.

Form Submission Flow

User Input Enter Information
→
Validation Check Form
→
Submit Trigger Event
→
Process Data Save / Send

Main Submission Concepts

1
Submit Event

Detect when the user submits the form.

2
Validation

Check whether the form is valid before processing.

3
Form Values

Access the values entered by the user.

4
Processing

Save the data or send it to another service.

Template-driven Form Submission

Template-driven forms commonly use the ngSubmit event to handle submission.

A template reference variable can provide access to the complete form and its current state.

Template
<form
    #enquiryForm="ngForm"
    (ngSubmit)="submitForm(enquiryForm)">

    <input
        type="text"
        name="name"
        ngModel
        required>

    <input
        type="email"
        name="email"
        ngModel
        required
        email>

    <button type="submit">

        Submit Enquiry

    </button>

</form>

Handling Template-driven Submission

Component
import { Component } from '@angular/core';
import { NgForm } from '@angular/forms';

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

    submitForm(form: NgForm) {

        if (form.valid) {

            console.log(
                form.value
            );

        }

    }

}

Validate Before Submission

The form should normally be checked before its values are processed.

When the form is invalid, the application can display validation messages instead of processing incomplete data.

Example
submitForm(form: NgForm) {

    if (form.invalid) {

        return;

    }

    console.log(
        form.value
    );

}

Tracking Submission State

Template-driven forms expose submission state through the form object.

The submitted state can be used to determine whether the form submission event has occurred.

Template
<p>

    Form Submitted:
    {{ enquiryForm.submitted }}

</p>

Reactive Form Submission

Reactive forms can handle submission using the normal Angular ngSubmit event while the form data is managed by a FormGroup.

The FormGroup provides direct access to the form model and its validation state.

Template
<form
    [formGroup]="registrationForm"
    (ngSubmit)="submitForm()">

    <input
        type="text"
        formControlName="name">

    <input
        type="email"
        formControlName="email">

    <button type="submit">

        Register

    </button>

</form>

Handling Reactive Form Submission

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

import {
    FormBuilder,
    Validators
} from '@angular/forms';

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

    registrationForm = this.fb.group({

        name: [
            '',
            Validators.required
        ],

        email: [
            '',
            [
                Validators.required,
                Validators.email
            ]
        ],

        course: [
            '',
            Validators.required
        ]

    ]);


    constructor(
        private fb: FormBuilder
    ) {
    }


    submitForm() {

        if (this.registrationForm.invalid) {

            return;

        }


        console.log(
            this.registrationForm.value
        );

    }

}

Accessing Submitted Form Values

After validation succeeds, the application's component can access the current form values.

These values can then be passed to a service or another application layer for further processing.

Reactive Form Values
const data =
    this.registrationForm.value;

console.log(data);

Submitted Data

Name: Pradnya

Email: pradnya@example.com

Course: Angular Full Stack

CIIT Training Institute Example

Suppose a visitor submits a course enquiry form on the CIIT Training Institute website.

Angular validates the form first. If the information is valid, the component can process the enquiry data.

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

import {
    FormBuilder,
    Validators
} from '@angular/forms';

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

    enquiryForm = this.fb.group({

        name: [
            '',
            Validators.required
        ],

        email: [
            '',
            [
                Validators.required,
                Validators.email
            ]
        ],

        mobile: [
            '',
            Validators.required
        ],

        course: [
            '',
            Validators.required
        ]

    });


    constructor(
        private fb: FormBuilder
    ) {
    }


    submitEnquiry() {

        if (this.enquiryForm.invalid) {

            this.enquiryForm.markAllAsTouched();

            return;

        }


        const enquiryData =
            this.enquiryForm.value;


        console.log(
            'CIIT Enquiry:',
            enquiryData
        );

    }

}
Template
<form
    [formGroup]="enquiryForm"
    (ngSubmit)="submitEnquiry()">


    <label>
        Name
    </label>

    <input
        type="text"
        formControlName="name">


    <label>
        Email
    </label>

    <input
        type="email"
        formControlName="email">


    <label>
        Mobile
    </label>

    <input
        type="text"
        formControlName="mobile">


    <label>
        Course
    </label>

    <select
        formControlName="course">

        <option value="">
            Select Course
        </option>

        <option value="Angular Full Stack">
            Angular Full Stack
        </option>

        <option value="Java Full Stack">
            Java Full Stack
        </option>

        <option value=".NET Full Stack">
            .NET Full Stack
        </option>

    </select>


    <button
        type="submit"
        [disabled]="enquiryForm.invalid">

        Send Enquiry

    </button>

</form>

CIIT Training Institute

Form Status: Valid

Course: Angular Full Stack

Submission: Enquiry Data Ready for Processing

Sending Form Data to a Service

In a real application, submitted form data is often passed to a service that communicates with the backend API.

Keeping this communication inside a service helps separate form handling from API-related logic.

Component
submitForm() {

    if (this.registrationForm.invalid) {

        return;

    }


    const data =
        this.registrationForm.value;


    this.registrationService
        .register(data)
        .subscribe({

            next: response => {

                console.log(
                    'Registration successful',
                    response
                );

            },

            error: error => {

                console.error(
                    'Registration failed',
                    error
                );

            }

        });

}

Handling Successful Submission

After successful processing, the application can display a confirmation message or clear the form.

The exact behavior depends on the application's requirements.

Example
submitForm() {

    if (this.registrationForm.invalid) {

        return;

    }


    const data =
        this.registrationForm.value;


    // Process data here

    console.log(
        'Submitted:',
        data
    );


    this.registrationForm.reset();

}

Reset Form After Submission

The form can be reset after successful processing when the application requires a fresh form.

Example
this.registrationForm.reset();

Prevent Invalid Submission

Example
submitForm() {

    if (this.registrationForm.invalid) {

        this.registrationForm
            .markAllAsTouched();

        return;

    }


    // Continue with valid data

}

Submission Rule

Invalid form: Do not process

Valid form: Process submitted data

Form Submission Steps

1
Collect

User enters information into the form.

2
Validate

Angular checks the configured validation rules.

3
Submit

The ngSubmit event calls the component method.

4
Process

Valid data is processed or sent to a service.

Template-driven vs Reactive Submission

Feature Template-driven Reactive
Submit Event ngSubmit ngSubmit
Form Access NgForm FormGroup
Values form.value formGroup.value
Validation Template-based Programmatic
Typical Use Simpler forms Complex forms

Submission Result Example

Form Submission Successful

Name: Pradnya

Course: Angular Full Stack

Form: Valid

Status: Data processed successfully

Important Points

1. Use ngSubmit

Use the Angular ngSubmit event to handle form submission.

2. Validate Before Processing

Check whether the form is valid before using the submitted values.

3. Access Form Values

Use the form or FormGroup value to access the information entered by the user.

4. Separate API Logic

Keep backend communication inside a service when the application grows.

Form Submission Best Practices

  • Validate form data before processing or sending it.
  • Keep submission logic inside a clear component method.
  • Use services for backend communication instead of placing API logic directly inside the template.
  • Display a useful success or error state after submission.
  • Reset the form only when the application requires it.
  • Perform validation on the backend as well; client-side validation should not be the only data-integrity check.

Summary

Angular form submission collects user-entered information and processes it after the form is submitted.

Template-driven forms commonly use ngSubmit with NgForm, while reactive forms use ngSubmit with a FormGroup.

The general workflow is Input → Validation → Submission → Processing. With this, the Angular Forms module is complete. The next module is Observables.