Last active
August 29, 2015 13:56
-
-
Save kristw/9302767 to your computer and use it in GitHub Desktop.
Pattern for defining angularjs filter
This file contains hidden or 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
define(['angular'], function (ng) { | |
'use strict'; | |
return ng.module('app.filters', []); | |
}); |
This file contains hidden or 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
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 | |
//--------------------------------------------------- | |
}); |
This file contains hidden or 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
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