Created
September 16, 2016 13:02
-
-
Save wlkns/111faf97bb18657fbf3445b3fe9fc4d9 to your computer and use it in GitHub Desktop.
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
;(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