var homeModule = angular.module('HomeModule', []);
homeModule.filter('titleCase', function(){
var titleCaseFilter = function(input){
var words = input.split(' ');
for(var i = 0; i < words.length; i++){
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
}
return words.join(' ');
};
return titleCaseFilter;
});
function HomeController($scope){
$scope.pageHeading = 'behold the majesty of you page title';
}
<body ng-app="HomeModule" ng-controller="HomeController">
<h1>{{pageHeading | titleCase}}</h1>
</body>
結果會看到第一個英文字都大寫.
沒有留言:
張貼留言