Skip to content

Instantly share code, notes, and snippets.

@SnisarOnline
Last active May 21, 2023 09:57
Show Gist options
  • Save SnisarOnline/373d26f53914f82cd313851cbea6bfe3 to your computer and use it in GitHub Desktop.
Save SnisarOnline/373d26f53914f82cd313851cbea6bfe3 to your computer and use it in GitHub Desktop.
Angular Pipe. Ограничение на количество символов. В случае привышения ставим ...
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