I want to create a list of items in my template, separated by commas, but I don\'t want the last item to have a comma:
one, two, three
How
I have just needed todo this but my value is in an attribute so the marked answer did not work.
Someone may find this helpful :
I used a pipe, I could have built the string up but felt a pipe would be more readable
CLI
ng g p Delimiter
Pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'delimiter'
})
export class DelimiterPipe implements PipeTransform {
transform(value: string, delimiter: string, isLast: boolean) {
return !isLast ? value + delimiter : value;
}
}
View
I needed some html in my view hence my need to use the attribute, eg