html部分:
<body ng-controller="chenController"> {{ filterValue | firstUppercase}} </body>
javascript部分:
var myApp = angular.module('chen',[]); myApp.controller('chenController',['$scope',function($scope){ $scope.filterValue ="you Look Great" ; }]); myApp.filter("firstUppercase",function(){ return function(input){ if(input){ return input[0].toUpperCase()+input.slice(1); } } });
预期的结果:
首字符大写 You look great