javascript - AngularJs filter:$viewValue is not handling html escaping -
if type in box, you'll see:
alabama missing text in bracket alaska fine arizona displays fine 1 time selected shows<
, >
any thought on how prevent filter sanitizing or (best) utilize proper encoding , decoding of html characters?
http://jsfiddle.net/zjpwe/64/
<div class="container"> <div ng-controller="mainctrl" class="row-fluid"> <form class="row-fluid"> <div class="container-fluid"> <input type="text" ng-model="selected" typeahead="state state in states | filter:$viewvalue" /> </div> </form> </div> </div>
...
angular.module('myapp', ['ui.bootstrap']) .controller("mainctrl", function ($scope) { $scope.selected = ''; $scope.states = ['alabama <where this>', 'alaska [this ok]', 'arizona <select me>']; });
one not-so-beautiful way solve issue apply filters sanitize array elements, , unsanitize them when selected.
http://jsfiddle.net/pwu0r81m/
$scope.$watch('selected', function() { $scope.selected = $scope.selected.replace(new regexp('<', 'g'), '<').replace(new regexp('>', 'g'), '>'); }); angular.module('myapp') .filter('sanitizer', function(){ homecoming function (items) { var filtered = []; angular.foreach(items, function(item){ filtered.push(item.replace(new regexp('<', 'g'), '<').replace(new regexp(">", 'g'), ">")); }); homecoming filtered; } });
javascript angularjs
No comments:
Post a Comment