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

ng-error-tooltips

v21.1.2

Published

Error-tooltips for Angular

Readme

ng-error-tooltips

npm version build status codecov

An Angular library for reactive forms that displays tooltips on form inputs with errors, providing a user-friendly way to visualize validation messages.

The latest library version is compatible with Angular 21.
Starting with version 20.1.0, ng-error-tooltips is fully zoneless-compatible.


Demo

https://mkeller1992.github.io/ng-error-tooltips/


Install

To install the library, enter the following command in your console:

npm i ng-error-tooltips

Setup

For apps based on standalone components

Import ErrorTooltipDirective directly in your component:

import { ErrorTooltipDirective } from '@ng-error-tooltips';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  imports: [ErrorTooltipDirective]
})
export class AppComponent {}

Usage

Define a reactive form with validators in your TypeScript component.
You can use validators from the CustomValidators class, which is part of this library.
For applications with language switching support, use the CustomValidatorsI18n variants instead.

import { Component, inject } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ErrorTooltipDirective, CustomValidators } from '@ng-error-tooltips';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss',
  imports: [FormsModule, ReactiveFormsModule, ErrorTooltipDirective],
})
export class AppComponent {

  private readonly formBuilder = inject(FormBuilder);

  formGroup: FormGroup = this.formBuilder.group({
    nameInput: new FormControl<string>('', {
      validators: [
        CustomValidators.required(),
        CustomValidators.minLength(3),
      ],
    }),
  });
}

Create the corresponding form in your HTML file and add ngErrorTooltip to the form fields where error tooltips should be displayed.

<form [formGroup]="formGroup" (ngSubmit)="submit()">

  <h4>Sample Form</h4>

  <input
    ngErrorTooltip
    formControlName="nameInput"
    placeholder="Enter your name*"
    type="text">

  <button type="submit">Submit</button>

</form>

Two ways to pass additional properties

You can pass separate properties, such as placement, as shown in the example below:

<input
  ngErrorTooltip
  [placement]="'right'"
  formControlName="nameInput"
  placeholder="Enter your name*"
  type="text">

Alternatively, you can pass one or more properties via an ErrorTooltipOptions object:

import { ErrorTooltipOptions } from '@ng-error-tooltips';

tooltipOptions: ErrorTooltipOptions = {
  placement: 'right',
};
<input
  formControlName="ageInput"
  ngErrorTooltip
  [options]="tooltipOptions"
  class="form-control"
  placeholder="Enter your age*"
  type="number">

Internationalisation (i18n)

Starting with version 21.1.0, ng-error-tooltips supports reactive multi-language error messages.

The library itself is intentionally lightweight regarding translations:

  • No dependency on ngx-translate or similar libraries
  • No internal language management
  • Fully signal-based and zoneless-friendly

Your application remains the single source of truth for the active language.

Default behaviour (no configuration)

If you do nothing, the tooltip falls back to German (de) error messages.

This guarantees backwards compatibility for existing applications.

Providing the active language

To enable language switching, provide the current language as a
Signal<'de' | 'fr' | 'en'> using provideErrorTooltips.

Example (standalone bootstrap):

import { bootstrapApplication, inject } from '@angular/core';
import { provideErrorTooltips } from '@ng-error-tooltips';
import { LanguageService } from './language.service';

export const currentLanguageCode = signal<SupportedLanguage>(defaultLanguage);

bootstrapApplication(AppComponent, {
  providers: [
    provideErrorTooltips({ lang: currentLanguageCode })
  ]
});

Whenever the language signal changes, all visible error tooltips update automatically.

Using i18n-aware validators

For applications with language switching, use the CustomValidatorsI18n variants.

import { CustomValidatorsI18n } from '@ng-error-tooltips';

formGroup = this.fb.group({
  name: ['', [
    CustomValidatorsI18n.requiredI18n(),
    CustomValidatorsI18n.minLengthI18n(3)
  ]]
});

Internally, these validators return tri-language payloads:

{
  de: 'Eingabe erforderlich',
  fr: 'Saisie requise',
  en: 'Input required'
}

The tooltip resolves the correct language automatically.

App-specific messages (regexPattern)

For domain-specific validation rules, all translations must be provided explicitly:

CustomValidatorsI18n.regexPatternI18n(
  /^[A-Z]{3}\d{4}$/,
  {
    de: 'Ungültiges Format',
    fr: 'Format invalide',
    en: 'Invalid format'
  }
);

This is intentional, as such messages are application-specific and cannot be provided by the library.

Mixing legacy and i18n validators

You can freely mix:

  • legacy validators (CustomValidators.required())
  • i18n validators (CustomValidatorsI18n.requiredI18n())

The tooltip handles both transparently.


Properties

| name | type | default | description | |-----|------|---------|-------------| | id | string | number | 0 | A custom id that can be assigned to the tooltip | | showFirstErrorOnly | boolean | false | Whether the tooltip should only display the first error if multiple errors exist | | placement | Placement | 'bottom-left' | The position of the tooltip | | zIndex | number | 1101 | The z-index of the tooltip | | tooltipClass | string | '' | Additional CSS classes applied to the tooltip (::ng-deep) | | shadow | boolean | true | Whether the tooltip has a shadow | | offset | number | 8 | Offset of the tooltip relative to the element | | width | string | '' | Fixed width of the tooltip | | maxWidth | string | '350px' | Maximum width of the tooltip | | pointerEvents | "auto" | "none" | 'auto' | Whether the tooltip reacts to pointer events |


Angular Jest unit tests

Mocking ErrorTooltipDirective

In unit tests, you may want to replace the real directive with the mock directive provided by the library.

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { ErrorTooltipDirective, MockErrorTooltipDirective } from '@ng-error-tooltips';
import { FormBuilder } from '@angular/forms';

describe('AppComponent', () => {
  let component: AppComponent;
  let fixture: ComponentFixture<AppComponent>;

  beforeEach(async () => {

    await TestBed.configureTestingModule({
      imports: [AppComponent],
      providers: [FormBuilder]
    })
    .overrideComponent(AppComponent, {
      remove: {
        imports: [ErrorTooltipDirective]
      },
      add: {
        imports: [MockErrorTooltipDirective]
      }
    })
    .compileComponents();

    fixture = TestBed.createComponent(AppComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });
});