Skip to content

Instantly share code, notes, and snippets.

@elqsar
Last active August 29, 2015 14:17
Show Gist options
  • Save elqsar/2c4a6c689f852c6787d2 to your computer and use it in GitHub Desktop.
Save elqsar/2c4a6c689f852c6787d2 to your computer and use it in GitHub Desktop.
'use strict';
angular.module('coolModule')
.directive('goFormatSpecialCharacters', function(){
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elem, attrs, ctrl) {
var PATTERN = /\&#{0,1}[A-Za-z0-9]+;/ig;
function format(input) {
if (input) {
if(input.match(PATTERN)) {
var transfromed = elem.html(input).text();
ctrl.$setViewValue(transfromed);
ctrl.$render();
return transfromed;
} else {
return input;
}
}
}
ctrl.$formatters.push(format);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment