如果您在框中输入A,您会看到:
<
和
>
有关如何防止过滤器消毒或(最佳)使用正确的html字符编码和解码的想法吗?
<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 for state in states | filter:$viewValue" />
</div>
</form>
</div>
</div>
...
angular.module('myApp', ['ui.bootstrap'])
.controller("mainCtrl", function ($scope) {
$scope.selected = '';
$scope.states = ['Alabama <Where is this>', 'Alaska [this is ok]', 'Arizona <Select Me>'];
});
答案 0 :(得分:0)
解决此问题的一种不那么漂亮的方法是应用过滤器来清理数组元素,然后在选中时将它们取消定位。
$scope.$watch('selected', function() {
$scope.selected = $scope.selected.replace(new RegExp('<', 'g'), '<').replace(new RegExp('>', 'g'), '>');
});
angular.module('myApp')
.filter('sanitizer', function(){
return function (items) {
var filtered = [];
angular.forEach(items, function(item){
filtered.push(item.replace(new RegExp('<', 'g'), '<').replace(new RegExp(">", 'g'), ">"));
});
return filtered;
}
});