{{ expression | filter }}
{{ expression | filter1 | filter2 | ... }}
{{ expression | filter:argument1:argument2:... }}
<span ng-repeat="a in array | filter ">
app.controller('testC',function($scope,currencyFilter){
$scope.num = currencyFilter(123534);
}
app.controller('testC',function($scope,$filter){
$scope.num = $filter('currency')(123534);
$scope.date = $filter('date')(new Date());
}
{{num | currency : '¥'}}
{{date | date : 'yyyy-MM-dd hh:mm:ss EEEE'}}
$scope.childrenArray = [
{name:'kimi',age:3},
{name:'cindy',age:4},
{name:'anglar',age:4},
{name:'shitou',age:6},
{name:'tiantian',age:5}
];
$scope.func = function(e){return e.age>4;}
{{ childrenArray | filter : 'a' }} //匹配属性值中含有a的
{{ childrenArray | filter : 4 }} //匹配属性值中含有4的
{{ childrenArray | filter : {name : 'i'} }} //参数是对象,匹配name属性中含有i的
{{childrenArray | filter : func }} //参数是函数,指定返回age>4的
{{ jsonTest | json}}
{{ childrenArray | limitTo : 2 }} //将会显示数组中的前两项
{{ num | number : 2 }}
<div>{{ childrenArray | orderBy : 'age' }}</div> //按age属性值进行排序
<div>{{ childrenArray | orderBy : orderFunc }}</div> //按照函数的返回值进行排序
<div>{{ childrenArray | orderBy : ['age','name'] }}</div> //如果age相同,按照name进行排序
app.filter('checkmark', function() {
return function(input) {
return input ? '\u2713' : '\u2718';
};
});
app.filter("truncate", function(){
return function(text, length){
if (text) {
var ellipsis = text.length > length ? "..." : "";
return text.slice(0, length) + ellipsis;
};
return text;
}
});
app.filter("highlight", function($sce, $log){
var fn = function(text, search){
$log.info("text: " + text);
$log.info("search: " + search);
if (!search) {
return $sce.trustAsHtml(text);
}
text = encodeURI(text);
search = encodeURI(search);
var regex = new RegExp(search, 'gi')
var result = text.replace(regex, '<span class="highlightedText">$&</span>');
result = decodeURI(result);
$log.info("result: " + result );
return $sce.trustAsHtml(result);
};
return fn;
});
app.factory("notifyService", function(){
var target = {
search:"key"
};
return target;
});
<div ng-controller="tools">
<div>
<input type="text" ng-model="notify.search" value=""/>
</div>
<div>
{{notify.search}}
</div>
</div>
app.controller("tools", function($scope, notifyService){
$scope.notify = notifyService;
});
<div ng-controller="search">
<div ng-bind-html="text | highlight:notify.search">
</div>
</div>
app.controller("search", function($scope, $log, notifyService){
$scope.text = "hello, world. hello, world. hello, world.";
$scope.notify = notifyService;
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有