I'm currently enhancing a truncate pipe in Angular that is supposed to cut off text after 35 words, but instead it's trimming down to 35 characters...
Here is the HTML code:
<p *ngIf="item.description.length > 0"><span class="body-12-bold">Description: </span><span>{{ description | truncate:[35] }}</span></p>
And here is the Transform Pipe:
@Pipe({name: 'truncate'})
export class TruncatePipe implements PipeTransform {
constructor(private item: SearchEntry, private config: ConfigService) { }
transform(value: string, args: string[]): string {
const limit = args.length > 0 ? parseInt(args[0], 10) : 20;
const trail = args.length > 1 ? args[1] : '...';
return value.length > limit ? value.substring(0, limit) + trail : value;
}
}