Ondrej Sika

Django filter truncatechars in AngularJS

10 Jan 2014

Prototype String class in CoffeeScript

String.prototype.truncatechars = (len)->
    this.substring(0, len)

or in JavaScript

String.prototype.truncatechars function(len){
    return this.substring(0, len);
}

Rewrite your django template from

<p>{ text|truncatechars: 20}}</p>

where {{ }} rendered by django template.

to

<p>{{ text.truncatechar(20) }}</p>

where {{ }} use AngularJS.

Share on Facebook, Twitter, Google+, Linkedin

comments powered by Disqus

--