//第一步,页面创建ng-app="investApp"
//第二步,页面引入angular-1.3.14.min.js 文件
//第三步,写下 下面代码部分
var investApp = angular.module('investApp',[]);
investApp.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 || ' …');
};
});
//第四步,页面使用
<a href="javascript:void(0);" title="{{invest.product_name}}" ng-bind="invest.product_name| cut:true:7:'...'" />
注意: 页面请使用ng-bind=""渲染,这样不至于一开始加载页面的时候有{{}}等被测试认为是乱码。