Last active
August 29, 2015 14:17
-
-
Save elqsar/2c4a6c689f852c6787d2 to your computer and use it in GitHub Desktop.
This file contains 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
'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