Angular Library That Helps You Show Message Error | ng-error-messages

ng-error-messages is a set of classes to help handle the error messages displayed in your form.

how to display error message in angular, angular validator set error message, angular reactive forms show validation errors on submit, reactive form error messages

This is the list of the supported validations

angular built-in validators

  • required
  • minlength
  • maxlength
  • pattern
  • min
  • max
  • email

Angular Validation Error Messages Cleaner | ngx-valdemort

How to make use of it:

Installation

npm install ng-error-messages --save

1. Import the ErrorMessageModule:

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { AppComponent }           from './app.component';
import { ErrorMessageModule } from 'ng-error-messages';

@NgModule({
  imports: [
    BrowserModule,
    HttpModule,
    ErrorMessageModule
  ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

2. Init the DisplayErrorService for your application:

import { Component } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { DisplayErrorService } from 'ng-error-messages'

@Component({
  selector: 'demo-app',
  templateUrl: 'index.component.html'
})
export class IndexComponent {
  form: FormGroup;
  valueFormated
  constructor(
    private displayErrorService: DisplayErrorService,
    private fb: FormBuilder) { }

  ngOnInit(): void {
    this.buildForm();
  }


  buildForm(): void {
    this.form = this.fb.group({
      'text': ['', [
        Validators.required,
        Validators.minLength(5),
        Validators.maxLength(10)
      ]]
    });
  }
  setLanguage(lang) {
    this.displayErrorService
      .setLanguage(lang)
      .subscribe(r => {
        console.log("change language")
      }, err => {
        alert(err)
      })
  }
}

3. Use it on your template:

<mat-card [formGroup]="form">
        <mat-card-title>
            Messager for errors
        </mat-card-title>
        <div>
                <input placeholder="Texto:" matInput formControlName="text">
                </input>
                <div errorMessage="text" alias="Super Texto" ></div>
        </div>
    </mat-card>

Custom Form Error Messages, ng-error-messages Plugin/Github, dynamic error message in angular


See Demo And Download

Official Website(ouracademy): Click Here

This superior jQuery/javascript plugin is developed by ouracademy. For extra advanced usage, please go to the official website.

Related Posts

Responsive-Multiple-Selection-Combo-Box-using-Bootstrap-3

Responsive Multiple Selection Combo Box using Bootstrap 3 | MagicSuggest

MagicSuggest is an easy-to-use jQuery plugin for creating a combo menu that allows you to select multiple items from a dropdown list with typing and auto-complete support….

material-design-tab-vanilla-js

Material Design Inspired Tab UI In Vanilla JavaScript

Material Design tab vanilla JS implements a material design-inspired tab component with a click ripple effect and an active sliding menu cursor. Must Read: Responsive Accessible Tabs…

countdown-timer-app

Simple Countdown Timer App In jQuery

The countdown is a front-end application that allows starting the countdown with two options: set a target date or write the number of countdown days. A countdown…

html5-animate-js

Add Animation to Your HTML5 Pages | animate.js

animate.js is a small JavaScript library that provides a convenient way to apply CSS animations powered by Animate.css to DOM elements without writing any CSS. Easily apply…

vue-responsive-parallax-cards

Responsive Hover Parallax Cards With Vuejs

Vue Responsive Parallax Cards Hover Create response cards with a scroll-triggered parallax effect in your Vue.js application. Must Read: jQuery Sliding Display Your Content Like a Deck…

pure-css-tabs-responsive

Responsive Pure CSS Only Accordion & Tabs Component

Responsive pure CSS accordion tabs and tabs will automatically convert to a vertical accordion interface on mobile devices. Must Read: Create Dynamic Accordion Giving JSON Data Using…