import { Component } from '@angular/core';
import { WrList, wrFormatList } from 'ngwr/pipes';
@Component({ imports: [WrList] })
export class MyComponent {}wrList
Join a list with the commas and the last "and" or "or" of the app locale.
Installation
Import the class. This entry point has no stylesheet.
Basic usage
join(', ') drops the last word and is wrong in every language. The pipe joins through Intl.ListFormat in LOCALE_ID.
<p>{{ names | wrList }}</p>
<p>{{ names | wrList: 'disjunction' }}</p>
<p>{{ parts | wrList: 'unit' }}</p>
<p>{{ parts | wrList: { type: 'unit', style: 'narrow' } }}</p>Playground
Blank items are left out. One item renders as it is, none as an empty string.
Ada, Alan, and Grace
{{ items | wrList: { type: 'conjunction', style: 'long' } }}Customize
Items, comma-separated
Type
Style
In TypeScript
wrFormatList gives the same text for a string built in code, in the locale you pass.
import { wrFormatList } from 'ngwr/pipes';
wrFormatList(['Ada', 'Alan', 'Grace'], 'en-GB'); // "Ada, Alan and Grace"
wrFormatList(['Ada', 'Alan', 'Grace'], 'en-GB', 'disjunction'); // "Ada, Alan or Grace"
wrFormatList(['Ада', 'Алан', 'Грейс'], 'ru'); // "Ада, Алан и Грейс"API
| Name | Description | Type | Default |
|---|---|---|---|
wrList | Joins the items through Intl.ListFormat in LOCALE_ID. Takes a type shortcut or the full options object. Blank items are left out; null, undefined and an empty list give an empty string. | (value: Iterable<string> | null | undefined, typeOrOptions: WrListType | Intl.ListFormatOptions = 'conjunction') => string | - |
wrFormatList | The pipe as a function, in the locale given. | (value: Iterable<string> | null | undefined, locale: string, typeOrOptions: WrListType | Intl.ListFormatOptions = 'conjunction') => string | - |
WrListType | What joins the last item: "and", "or", or nothing, for a compound unit. | 'conjunction' | 'disjunction' | 'unit' | 'conjunction' |
options.style | How much of the joining word is written, as Intl.ListFormat reads it. | 'long' | 'short' | 'narrow' | 'long' |