<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="https://cdn.bootcss.com/angular.js/1.4.6/angular.min.js"></script>
<script type="text/javascript" src="pagingCtrl.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p >名字是:{{name | myfilter:3 }}</p>
</div>
</body>
</html>
var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope,$window) {
});
/**
* 过滤器
*/
app.filter("myfilter", function () {
//obj 被过滤的对象,len 长度
return function(obj,len){
//返回结果
var str;
if(obj == null || undefined == obj || obj.length == 0){
return str="返回默认值";
}else{
return str=obj.substr(0,len);
}
return str;
}
});