zoukankan      html  css  js  c++  java
  • AngularJS自定义过滤器

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>自定义过滤器</title>
    	<script src="angular-1.5.8.min.js"></script>
    	<style>
    		* {
    			margin: 0;
    			padding: 0;
    			list-style: none;
    		}
    		ul {
    			 800px;
    			margin: 100px auto 0;
    		}
    		.odd {
    			color: red;
    		}
    		.even {
    			color: blue;
    		}
    	</style>
    </head>
    <body ng-app="myApp">
    	<div ng-controller="myCtrl"ng-init="score=95">
    		<ul>
    			<li>请输入性别:<input type="text" ng-model="input"></li>
    			<li>请输入年龄:<input type="text" ng-model="input1"></li>
    			<li>请输入姓名:<input type="text" ng-model="input2"></li>
    			<li ng-repeat="item in data | filter: input | filter: {age: input1} | filter: {name: input2}" ng-class-odd="'odd'" ng-class-even="'even'">
    				<span>name: {{item.name}}</span>
    				<span>sex: {{item.sex}}</span>
    				<span>age: {{item.age}}</span>
    			</li>
    		</ul>
    	</div>
    
    	<script>
    		var app = angular.module("myApp",[]);
    		app.controller("myCtrl", ["$scope", function (scope) {
    			scope.data = [
    				{'name':'Han','sex':'男','age': 22},
    				{'name':'Zhang','sex':'女','age': 23},
    				{'name':'Han','sex':'男','age': 0},
    				{'name':'Han','sex':'男','age': 22},
    				{'name':'Zhang','sex':'女','age': 23},
    				{'name':'Han','sex':'男','age': 0}
    			]
    		}]);
    		app.filter('myfilter', function () {
    			return function (input) {
    				var arr = [];
    				for (var i = 0; i < input.length; i++) {
    					if (input.sex == "男") {
    						arr.push(input[i]);
    					}
    				}
    				return arr;
    			}
    		});
    	</script>
    </body>
    </html>
    

      

  • 相关阅读:
    数据库课程设计_购书管理系统代码(sql_c#及sql_java)
    你离不开的数组
    getchar的用法
    字母大小写转化
    C语言乘除颠覆你的世界观
    循环的执行过程、适用情况和常见错误
    斐波那契数和数小方块的类型题分析方法
    C语言刷题需要注意的地方
    函数那些事
    逻辑与、或、非的使用方法
  • 原文地址:https://www.cnblogs.com/handsomehan/p/6148568.html
Copyright © 2011-2022 走看看