Skip to content

Instantly share code, notes, and snippets.

@leocaseiro
Last active August 29, 2015 14:21
Show Gist options
  • Save leocaseiro/696b66d82738ac2af365 to your computer and use it in GitHub Desktop.
Save leocaseiro/696b66d82738ac2af365 to your computer and use it in GitHub Desktop.
Angular Custom Filter
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<title>Angular Custom Filter</title>
</head>
<body>
<div ng-controller="Filter">
<p>{{text | clean:'-':'.jpg'}}</p>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js"></script>
<script>
angular.module('MyApp', [])
.filter('clean', function(){
return function(input, separator, suffix){
input = input
.toLowerCase()
.replace(/\s+/g, separator || '-') + suffix;
return input;
};
})
.controller('Filter', function($scope){
$scope.text = "Hello World! That a beautiful day.";
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment