Open In App

Angular 10 NgPlural Directive

In this article, we are going to see what is NgPlural in Angular 10 and how to use it.

The NgPlural in Angular10 is used to Add or remove DOM sub-trees based on a numeric value.



Syntax:

<li *NgPlural='condition'></li>

NgModule: Module used by NgPlural is:



 

Selectors:

Approach: 

Example:




import { Component, Inject } from '@angular/core';
import { PLATFORM_ID } from '@angular/core';
import { isPlatformWorkerApp } from '@angular/common';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  val = 1;
}




<some-element [ngPlural]="val">
    <ng-template ngPluralCase="=1">Geek</ng-template>
    <ng-template ngPluralCase="=2">Geeks</ng-template>
  </some-element>

Output:

Geek

Reference: https://angular.io/api/common/NgPlural

Article Tags :