Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Angular JS little filters.
'use strict';
angular.module('foo', [])
.filter('substring', function() {
return function(str, start, end) {
return str.substring(start, end);
};
})
.filter('zpadding', function() {
return function(num, digit) {
while(num.toString().length < digit){
num = '0' + num.toString();
}
return num;
};
});
<!doctype html>
<html ng-app="foo">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
<script type="text/javascript" src="https://gist.github.com/mugifly/4942965/raw/angular-filters.js"></script>
<script type="text/javascript">
function fooCtrl($scope) {
$scope.bar = "abcdefghijklmnopqrstuvwxyz";
$scope.num = 123;
}
</script>
</head>
<body ng-controller="fooCtrl">
<h2>substring</h2>
<p> {{bar}} </p>
<p> {{bar | substring:15}} </p>
<p> {{bar | substring:0:5}} </p>
<h2>zpadding</h2>
<p> {{num}} </p>
<p> {{num | zpadding:4}} </p>
<hr>
<a href="https://gist.github.com/mugifly/4942965/">https://gist.github.com/mugifly/4942965/</a>
</body>
</html>
@monk8800

This comment has been minimized.

Copy link

@monk8800 monk8800 commented Sep 10, 2015

Thanks for the gist it helped me out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.