Skip to content

Instantly share code, notes, and snippets.

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">
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
function fooCtrl($scope) {
$ = "abcdefghijklmnopqrstuvwxyz";
$scope.num = 123;
<body ng-controller="fooCtrl">
<p> {{bar}} </p>
<p> {{bar | substring:15}} </p>
<p> {{bar | substring:0:5}} </p>
<p> {{num}} </p>
<p> {{num | zpadding:4}} </p>
<a href=""></a>

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.