Skip to content

Instantly share code, notes, and snippets.

@wen-dell
Created February 7, 2018 01:31
Show Gist options
  • Save wen-dell/aee37777967d7cb3dbaa0809a29b7877 to your computer and use it in GitHub Desktop.
Save wen-dell/aee37777967d7cb3dbaa0809a29b7877 to your computer and use it in GitHub Desktop.
Pluralizing words in Angular
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'plural'
})
export class PluralPipe implements PipeTransform {
transform(value: any, args?: any): any {
return value > 1 ? `${value} ${args}s` : `${value} ${args}`;
}
// How to use it in a template:
// <p>There are {{ quantity | plural:"student" }} in my school</p>
// The word 'student' will be pluralized if the quantity is bigger than 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment