Created
October 8, 2018 21:14
-
-
Save odahcam/e427e40d3ed7b9daa2bda27e31d6facf to your computer and use it in GitHub Desktop.
Angular 6 Pipe that gets only the first word of a string.
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: 'firstWord' | |
}) | |
export class FirstWordPipe implements PipeTransform { | |
transform(value: string): string { | |
if (!value) { return ''; } | |
return value.split(' ')[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks