Created
September 25, 2017 16:29
-
-
Save hatemhosny/931f0525ee823ad033280379b4468be5 to your computer and use it in GitHub Desktop.
TruncatePipe
This file contains 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 TruncatePipe implements PipeTransform { | |
transform(value: string, limit = 250, trail = '...'): string { | |
if (value.length > limit) { | |
return value.substring(0, limit) + trail; | |
} else { | |
return value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment