Skip to content

Instantly share code, notes, and snippets.

@salmanx
Created November 23, 2017 07:42
Show Gist options
  • Save salmanx/2475b587a7413bcd9de5dd4d8db82d7c to your computer and use it in GitHub Desktop.
Save salmanx/2475b587a7413bcd9de5dd4d8db82d7c to your computer and use it in GitHub Desktop.
Custom pipe for showing summary text in angular
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: "excerpt"
})
export class ExcerptPipe implements PipeTransform{
transform(text: string, limit?: number){
if(!text) return null;
let desiredLimit = (limit) ? limit : 50;
return text.substr(0, desiredLimit) + '...';
}
}
// exapmle: {{ text | excerpt : 10 }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment