AngularJS - 自定义过滤器

将字符串的首字母大写 , 其他字母小写 

 1 var app = angular.module('demoApp', []);
 2 
 3 app.filter('demoFilter', function() {
 4     
 5     return function(obj) {
 6 
 7         var str = obj.toLowerCase(); // 先将字符串转为小写
 8 
 9         str = str[0].toUpperCase() + str.substring(1, str.length); 
10 
11         return str ;
12     };
13 });
1 <h1>{{ "abcdefg" | demoFilter }}</h1>
2 <!-- Abcdefg -->

猜你喜欢

转载自www.cnblogs.com/mpci/p/11022604.html