JSAngular-14

building filters

by munir

HTML

<html ng-app='myApp'>
    <div ng-controller="Filter">
        <p>{{text | clean:'+'}}</p>
    </div>
    
    <script>
        angular.module('myApp',[])
        .filter('clean',function(){
            return function(input,separator){
                var filter = new RegExp('[^a-z0-9' + (separator || '-') + ']','ig');
                return input.toLowerCase()
                    .replace(/\s+/g, (separator || '-'))
                    .replace(filter, '');
            };
        })
        .controller('Filter',function($scope){
            $scope.text = 'Hello World, this is some text!';
        });
        
    </script>
</html>