首页 > Web开发 > 详细

angularjs自定义过滤器

时间:2015-04-08 11:15:06      阅读:264      评论:0      收藏:0      [点我收藏+]

angularjs中的自定一过滤器很有必要掌握,我觉得相当于后端语言中的模板函数概念,在模板中定义是这样的<div>{{user | myfilter:user}}</div>,然后myfilter就是我们定义的一个模板函数,他专门处理某种计算,下面看看他的demo

<!DOCTYPE html>
<html>
<head>
	<title>angularJS demo</title>
	<meta charset="utf-8">		
</head>
<body>

	<form ng-app="myapp" name="myForm" ng-controller="test">
		<div>{{user | myfilter:user}}</div>
	</form>

	<script src="//www.w3cschool.cc/try/angularjs/1.2.5/angular.min.js"></script>
	<script type="text/javascript">
	function test($scope){
		$scope.user = "张三";
		$scope.email = "341234213@qq.com";
	}

	var app = angular.module("myapp",[]).controller("test",test).
		filter("myfilter",function() {
			return function(obj,args){
				console.log(obj,args);
				return "处理后的对象";
			}
	});
	</script>
	
</body>	
</html>




angularjs自定义过滤器

原文:http://my.oschina.net/tongjh/blog/397192

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!