npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ngx-mat-form-errors

v1.0.0

Published

A lightweight Angular library that automatically displays validation errors for Angular Material forms. Stop writing repetitive error message logic!

Readme

ngx-mat-form-errors

A lightweight Angular library that automatically displays validation errors for Angular Material forms. Stop writing repetitive error message logic!

npm version npm downloads Live Demo

Live Demo

🚀 See it in action!

Check out the live demo on CodeSandbox where you can experiment with the library:

Open in CodeSandbox

The demo includes:

  • ✅ Email field with required & email validation
  • ✅ Password field with required & minlength validation
  • ✅ Real-time error messages
  • ✅ Fully editable code

Installation

npm install ngx-mat-form-errors

Quick Usage

1. Import the module

For standalone components:

import { NgxFormErrorsModule } from 'ngx-mat-form-errors';

@Component({
  // ...
  imports: [
    // ... other imports
    NgxFormErrorsModule,
    ReactiveFormsModule,
    MatFormFieldModule,
    MatInputModule
  ]
})
export class YourComponent {}

For NgModules:

import { NgxFormErrorsModule } from 'ngx-mat-form-errors';

@NgModule({
  imports: [
    // ... other imports
    NgxFormErrorsModule,
    ReactiveFormsModule,
    MatFormFieldModule,
    MatInputModule
  ]
})
export class AppModule {}

2. Create a form

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

export class YourComponent {
  form: FormGroup;

  constructor(private fb: FormBuilder) {
    this.form = this.fb.group({
      email: ['', [Validators.required, Validators.email]],
      password: ['', [Validators.required, Validators.minLength(8)]]
    });
  }
}

3. Add to template

<form [formGroup]="form">
  <!-- Email field -->
  <mat-form-field>
    <mat-label>Email</mat-label>
    <input matInput formControlName="email">
  </mat-form-field>
  <ngx-error field="email" label="Email"></ngx-error>

  <!-- Password field -->
  <mat-form-field>
    <mat-label>Password</mat-label>
    <input matInput type="password" formControlName="password">
  </mat-form-field>
  <ngx-error field="password" label="Password"></ngx-error>
</form>

That's it! Errors will automatically show when fields are invalid and touched.

Examples

Basic Form

<mat-form-field>
  <mat-label>Username</mat-label>
  <input matInput formControlName="username">
</mat-form-field>
<ngx-error field="username" label="Username"></ngx-error>

Custom Label

<ngx-error field="email" label="Email address"></ngx-error>
<!-- Displays: "Email address is required" instead of "Email is required" -->

Nested Form Groups

<div formGroupName="address">
  <mat-form-field>
    <mat-label>Street</mat-label>
    <input matInput formControlName="street">
  </mat-form-field>
  <ngx-error field="address.street" label="Street"></ngx-error>
</div>

Default Error Messages

| Error | Message | |-------|---------| | required | {label} is required | | email | Invalid email format | | minlength | {label} must be at least {requiredLength} characters | | maxlength | {label} cannot exceed {requiredLength} characters | | pattern | Invalid {label} format | | default | Invalid {label} |

Custom Error Messages

Create a custom service:

import { Injectable } from '@angular/core';
import { ErrorService } from 'ngx-mat-form-errors';

@Injectable({ providedIn: 'root' })
export class CustomErrorService extends ErrorService {
  override getErrorMessage(errors: any, label: string): string {
    if (errors['required']) return `Please enter your ${label}`;
    if (errors['email']) return 'Enter a valid email address';
    if (errors['minlength']) return `Minimum ${errors['minlength'].requiredLength} characters required`;
    return super.getErrorMessage(errors, label);
  }
}

Add to providers:

providers: [
  { provide: ErrorService, useClass: CustomErrorService }
]

API

<ngx-error> Component

| Property | Type | Required | Description | |----------|------|----------|-------------| | field | string | Yes | Form control name (supports nested like "address.street") | | label | string | No | Display name (defaults to field name) |

Styling

The component uses the .ngx-error class:

.ngx-error {
  color: #f44336;
  font-size: 12px;
  margin-top: 4px;
}

Requirements

  • Angular 14+
  • @angular/forms
  • @angular/material (optional)