Skip to content

Instantly share code, notes, and snippets.

@yllieth
Created November 6, 2014 10:59
Show Gist options
  • Save yllieth/e16ed2d35deab6f47eec to your computer and use it in GitHub Desktop.
Save yllieth/e16ed2d35deab6f47eec to your computer and use it in GitHub Desktop.
Angular filter to extract extension from a file
angular.module('tools.filter')
.filter('extension', function() {
return function(input) {
return input.split('.').pop()
};
});
@yllieth
Copy link
Author

yllieth commented Nov 6, 2014

Usage : {{ filename | extension }}

It assumes:

  • you have extension.js file include in your main HTML file
  • your application loads tools.filter module angular.module('myApp', [tools.filter])
  • filename is accessible and is a String (like file.txt)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment