我一直在尝试找出如何从使用过滤器的ng-options生成的数组中排除一个值。
下面的代码片段生成的数组生成了下面的数组["publicExtra","public","private"],我想从选项中排除"public“。提前谢谢。
<select ng-model="elb_instance.use_vpc"
ng-options="('Subnet: ' + type) for type in elb_instance.vpc_names_with_subnet_types_for_elb[elb_instance.vpc_name]"
ng-disabled="!elb_instance['new_record?']"
ng-show="elb_instance.vpc_name"
id="use_vpc"
class="input-medium">发布于 2020-05-01 22:41:50
您可以很容易地使用filter和在搜索字符串之前使用!来否定谓词,如下所示:
ng-options="('Subnet: ' + type) for type in types | filter: '!public'">但请注意,这会忽略public和publicExtra,因为基本筛选器不会进行精确匹配。为此,我们还需要传递comparator的true,如下所示:
ng-options="('Subnet: ' + type) for type in types | filter: '!public' : true">
var app = angular.module('myApp', []);
app.controller('AppCtrl', function($scope) {
$scope.selected = "";
$scope.types = ["publicExtra","public","private"];
});<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<section ng-app="myApp">
<div ng-controller="AppCtrl">
<select ng-model="selected"
ng-options="('Subnet: ' + type) for type in types | filter: '!public' : true">
</select>
</div>
</section>
https://stackoverflow.com/questions/61544326
复制相似问题