<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>模糊查询</title>
<script type="text/javascript" src="js/angular.min.js" ></script>
</head>
<body ng-app="myapp" ng-controller="mysrl">
<input type="text" ng-model="name" /><br />
{{names|mohu:name}}<!--mohu是自定义过滤器,name是条件,names是过滤的数组-->
<script type="text/javascript">
var mo=angular.module("myapp",[]);
mo.controller("mysrl",function($scope){
$scope.names=["张三","李四","李四1","李四2","张三2"];
});
mo.filter("mohu",function(){
return function(names,n){
//新建一个数组用于保存符合的信息
var newname=[];
for(var i=0;i<names.length;i++){
//获取数组的元素
var na=names[i];
//判断是否符合
if(na.indexOf(n)!=-1){
//添加到新集合
newname.push(na);
}
}
//返回新集合
return newname;
}
});
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>模糊查询</title>
<script type="text/javascript" src="js/angular.min.js" ></script>
</head>
<body ng-app="myapp" ng-controller="mysrl">
<input type="text" ng-model="name" /><br />
{{names|mohu:name}}<!--mohu是自定义过滤器,name是条件,names是过滤的数组-->
<script type="text/javascript">
var mo=angular.module("myapp",[]);
mo.controller("mysrl",function($scope){
$scope.names=["张三","李四","李四1","李四2","张三2"];
});
mo.filter("mohu",function(){
return function(names,n){
//新建一个数组用于保存符合的信息
var newname=[];
for(var i=0;i<names.length;i++){
//获取数组的元素
var na=names[i];
//判断是否符合
if(na.indexOf(n)!=-1){
//添加到新集合
newname.push(na);
}
}
//返回新集合
return newname;
}
});
</script>
</body>
</html>