我一直在尝试如何从ng-options生成的数组中使用过滤器排除一个值,但没有成功。
下面的代码段生成的数组会生成以下数组。["publicExtra","public","private"]
我想把 "公共 "从选项中排除。先谢谢你了。
<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">
你可以使用 filter
并使用 !
在搜索字符串前否定谓词like。
ng-options="('Subnet: ' + type) for type in types | filter: '!public'">
但请注意,这将同时忽略 public
&.作为基本的过滤器,不能做到完全匹配。publicExtra
因为基本过滤器不做精确匹配。为此,我们还需要通过 true
对于 comparator
喜欢。
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>