Created
October 5, 2016 18:22
-
-
Save mangar/aa55c72e5d36772098d94f44aa979287 to your computer and use it in GitHub Desktop.
Truncate Pipe for Angular2
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: 'truncate'}) | |
| export class Truncate implements PipeTransform { | |
| transform(value: string, args: string[]) : string { | |
| let limit = args.length > 0 ? parseInt(args[0], 10) : 10; | |
| let trail = args.length > 1 ? args[1] : '...'; | |
| return value.length > limit ? value.substring(0, limit) + trail : value; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
{{model.name | truncate : 15 : '.'}}