Last active
August 29, 2015 14:21
-
-
Save leocaseiro/696b66d82738ac2af365 to your computer and use it in GitHub Desktop.
Angular Custom Filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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