a8m / angular-filter

Bunch of useful filters for AngularJS (with no external dependencies!)
https://github.com/a8m/angular-filter
MIT License
2.93k stars 332 forks source link

ltrim and rtrim #265

Open MaccerC opened 6 years ago

MaccerC commented 6 years ago

Is it possible to trim a number of characters and not only a certain part of a string?

RSchneyer commented 6 years ago

I don't know if you still care, but I managed to trim a number of characters with the truncate and reverse filters.

$scope.message = 'Hello World'
<p>{{message| reverse | truncate: message.length - 7 | reverse}}</p>

results in "orld", which is the same as removing 7 characters from the left. If you want to remove characters from the right, you can just use truncate.

<p>{{message | truncate: message.length - 7}}</p>

results in "Hell"