Last active
May 21, 2023 09:57
-
-
Save SnisarOnline/373d26f53914f82cd313851cbea6bfe3 to your computer and use it in GitHub Desktop.
Angular Pipe. Ограничение на количество символов. В случае привышения ставим ...
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: "limitSymbols" | |
}) | |
export class limitSymbols implements PipeTransform { | |
/** | |
* ограничение выводимых символов с добавлением троеточия | |
* Example used: | |
* <h3 [innerHTML]="news.name | limitSymbols:39"></h3> | |
* <h3>{{news.name | limitSymbols:39}}</h3> | |
*/ | |
transform(string, limit) { | |
if (string.length > limit) { | |
return string.slice(0, limit) + " ..."; | |
} | |
return string; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment