Skip to content

Instantly share code, notes, and snippets.

@kristw
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristw/9302767 to your computer and use it in GitHub Desktop.
Save kristw/9302767 to your computer and use it in GitHub Desktop.
Pattern for defining angularjs filter
define(['angular'], function (ng) {
'use strict';
return ng.module('app.filters', []);
});
define([
// Umbrella module
'./filters',
// If you create a new filter and want to use in angular
// Please add it to the list below, in alphabetical order.
'./sample-filter'
],
function(filters){
//---------------------------------------------------
// BEGIN code for this module
//---------------------------------------------------
var args = Array.prototype.slice.call(arguments, 1);
// For each of the filters listed above
args.forEach(function(filter){
// Create angular filter with
// filter name = filter.name
// filter function = filter.filter
filters.filter(filter.name, function(){
return filter.filter;
});
});
return filters;
//---------------------------------------------------
// END code for this module
//---------------------------------------------------
});
define([
],
function () {
'use strict';
//---------------------------------------------------
// BEGIN code for this filter
//---------------------------------------------------
return{
name: 'sampleFilter',
filter: function(input, params) {
return input + ' *sample*';
}
};
//---------------------------------------------------
// END code for this filter
//---------------------------------------------------
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment