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>
    

      

  • 相关阅读:
    ajax请求
    easyui相关问题
    linux解压命令
    angular2 中文学习资料整理
    在angular2服务中注入服务
    Angular 2模板语法
    登录,注册流程(基于token的身份验证)
    Node Js与JavaScript的区别及nodejs优缺点。
    yarn包管理网站
    浅谈Cookie,Session,WebStorage区别,应用场景
  • 原文地址:https://www.cnblogs.com/handsomehan/p/6148568.html
Copyright © 2011-2022 走看看