Created
November 23, 2017 07:42
-
-
Save salmanx/2475b587a7413bcd9de5dd4d8db82d7c to your computer and use it in GitHub Desktop.
Custom pipe for showing summary text in angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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