Friday, 24 April 2015

Trim data in angularjs

If we want to trim data in angularjs and data fetched from the back-end then,include following filter in controller.js


 controller.js


.filter('cut', function () {
return function (value, wordwise, max, tail) {
if (!value) return '';

max = parseInt(max, 10);
if (!max) return value;
if (value.length <= max) return value;

value = value.substr(0, max);
if (wordwise) {
var lastspace = value.lastIndexOf(' ');
if (lastspace != -1) {
value = value.substr(0, lastspace);
}
}

return value + (tail || ' …');
};
});


And where you want to trim data in html page ,please include following:-

 a)If you want to ignore some later after spaces
{{expression.name| cut:true:100:'...' }}

b) If you want complete data
{{expression.name| cut:false:100:'...' }}

No comments:

Post a Comment