Skip to content

Instantly share code, notes, and snippets.

@wlkns
Created September 16, 2016 13:02
Show Gist options
  • Save wlkns/111faf97bb18657fbf3445b3fe9fc4d9 to your computer and use it in GitHub Desktop.
Save wlkns/111faf97bb18657fbf3445b3fe9fc4d9 to your computer and use it in GitHub Desktop.
;(function() {
'use strict';
angular.module('app').filter('address', Filter);
function Filter($sce) {
return function(input, seperator, defaultValue) {
seperator = seperator || ', ';
defaultValue = defaultValue || '';
if (typeof input !== 'object')
{
return defaultValue;
}
var parts = ['address', 'address2', 'city', 'county', 'country', 'postcode'], output = [];
for(var key in parts)
{
if (input.hasOwnProperty(parts[key]) && input[parts[key]].length)
{
output.push(input[parts[key]]);
}
}
return $sce.trustAsHtml(output.length ? output.join(seperator) : defaultValue);
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment