您的位置:首页 > 其它

Cordova学习笔记 filter的使用

2017-03-14 15:10 281 查看
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<script src="js/angular.js"></script>
<script type="application/javascript">
(function(angular) {
'use strict';
var myApp =angular.module('myApp', []);
myApp.filter('getBig',function(){
return function(a,b){
if(a>b) return a;else return b;
}
});
myApp.controller('firstController', function firstController($scope,$filter) {
$scope.arra = ['a','b','C','D']
$scope.testname = $filter('uppercase')('yeah');<!--使用过虑器服务-->
$scope.testname2 =$filter('getBig')(3,4);
$scope.childrenArray = [
{name:'a',age:3},
{name:'b',age:4},
];
});

})(window.angular);//主模块

window.onload = function(){
var myAppdiv = document.getElementById('myApp22');
angular.bootstrap(myAppdiv,['myApp']) //动态的绑定主mudule的html作用范围
}
</script>
</head>
<body >
<div id="myApp22">
<div ng-controller="firstController">
<ul>
<li ng-repeat="a in arra">{{a|uppercase}}</li><!--转换成大写-->
</ul>
<ul>
<li ng-repeat="a in arra">{{a|lowercase}}</li><!--转换成小写-->
</ul>

<div>{{ 1464285948024 | date:"yyyy-MM-dd hh:mm:ss"  }} </div><!--时间戳转换格式-->
<div>{{ 1.34567 | number:3 }}</div><!--保留三位小数-->
<div>{{ "abdcefefdf" | limitTo:6 }} </div><!--从前面截取6个字符-->
<div>{{ "abdcefefdf" | limitTo:-4 }} </div><!--从后面截取4个字符-->
<div>`testname`</div>
<div>`testname2`</div>
<div>`tn1`</div>

<table>
<tr ng-repeat="ca in childrenArray | orderBy:'-age'">
<td>`ca`.`name`</td>
<td>`ca`.`age`</td>
</tr>
</table>

</div>
</div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Cordova filter