【发布时间】:2017-07-29 02:03:43
【问题描述】:
我正在使用 ui-select 库中的选择字段。我可以选择选项或输入一个新选项。当我输入一个新值并尝试通过再次单击该字段来编辑它时,手动输入的值就消失了。是否有任何可用的方法,以便我可以保留手动输入的值并同时对其进行编辑。我已经参考了以下 stackoverflow 问题来实现它。 Allow manually entered text in ui-select
HTML
<ui-select ng-model="superhero.selected">
<ui-select-match placeholder="Select or search a superhero ...">{{$select.selected}}</ui-select-match>
<ui-select-choices repeat="hero in getSuperheroes($select.search) | filter: $select.search">
<div ng-bind="hero"></div>
</ui-select-choices>
</ui-select>
控制器
$scope.getSuperheroes = function(search) {
var newSupes = $scope.superheroes.slice();
if (search && newSupes.indexOf(search) === -1) {
newSupes.unshift(search);
}
return newSupes;
}
下面的链接https://codepen.io/arcotnaresh/pen/bVqqdj已经有一个工作的codepen解决方案了
【问题讨论】:
标签: angularjs