This page demonstrate the custom filter, titlecase that was created to change the content to Title Case (first letter of each word is converted to capital case). Refer to notes section and code samples to understand key aspects required to create a custom filter. Refer AngularJS page on filters to understand about filters and how to create custom filter.



Custom Filter Code Example
<!DOCTYPE html>

<html ng-app="HelloApp">
<body ng-controller="HelloCtrl">
<input type="text" ng-model="name"/>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
// Code defining custom module consisting of a filter
// The module needs to be included as dependency for using the filter, titlecase
angular.module('CustomFilterModule', [])
.filter( 'titlecase', function() {
return function( input ) {
return input.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
// Angular App on this page
// Included CustomFilterModule as dependency
angular.module('HelloApp', [ 'CustomFilterModule'])
.controller('HelloCtrl', ['$scope', function($scope){
$ = '';
comments powered by Disqus