AngularJS - 如果ng-option为空,则隐藏<select>元素</select>

时间:2015-01-29 09:44:29

标签: javascript angularjs

如果使用过滤器后<select>变量为空,是否可以隐藏ng-options元素?

<select class="form-control" 
        ng-model="selected" 
        ng-options="property.pstSnr.description for property in leistobToProperties | filter: {grouping:1}">
</select>

如果<select>的所有选项都为空,则property.pstSnr.description元素不应显示。

感谢。

3 个答案:

答案 0 :(得分:2)

您可以定义已过滤的列表,然后在ng-show

中使用它
<select class="form-control" 
        ng-show="filteredSet" 
        ng-model="selected"
        ng-options="property.pstSnr.description for property in filteredSet = (leistobToProperties | filter: filtering)">
</select>

JS Fiddle

答案 1 :(得分:0)

也许

<select class="form-control" ng-model="selected" ng-show="filtered.pstSnr.description.length > 0" ng-options="property.pstSnr.description for property in filtered = (leistobToProperties | filter: {grouping:1})"></select>

答案 2 :(得分:0)

如果没有选项,我有一个选择隐藏

<select id="categorylist" focus-on="focusMe" ng-change="UpdateDowntimeEvent()" class="col-md-11" name="CategoryId" ng-model="Model.CurrentDowntime.CategoryId" ng-options="downtimeCategory.CategoryId as downtimeCategory.CategoryName group by downtimeCategory.Node  for downtimeCategory in Model.DowntimeCategories" required="" ng-hide="Model.DowntimeCategories ==0" >

你可以试试这个

<select class="form-control" ng-model="selected" ng-options="property.pstSnr.description for property in leistobToProperties | filter: {grouping:1}" ng-hide=" property.leistobToProperties == 0"></select>