Last active
September 5, 2018 17:55
-
-
Save mugifly/4942965 to your computer and use it in GitHub Desktop.
Angular JS little filters.
This file contains 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
'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; | |
}; | |
}); |
This file contains 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="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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the gist it helped me out