Limit the length of a string with AngularJS

Alan2 picture Alan2 · Aug 7, 2013 · Viewed 289.5k times · Source

I have the following:

<div>{{modal.title}}</div>

Is there a way that I could limit the length of the string to say 20 characters?

And an even better question would be is there a way that I could change the string to be truncated and show ... at the end if it's more than 20 characters?

Answer

Govan picture Govan · Sep 17, 2014

Here is the simple one line fix without css.

{{ myString | limitTo: 20 }}{{myString.length > 20 ? '...' : ''}}