angularjs控制字符串长度超过指定长度后面内容以省略号显示
angular.module('ng').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 || ' …'); }; });
<div ng-bind="val.title | cut:true:33:' ...'"> </div>
或者
<div>{{val.title | cut:true:33:' ...'}}</div>