2016-04-13 39 views
5
<body ng-app> 
<datalist id="dataList"> 
    <select id="select"> 
    <option ng-repeat="val in temp" ng-hide="true" >{{val}}</option> 
    </select> 
</datalist>        
<input list="dataList" ng-model="fromLocation" /> 
</body> 

http://jsfiddle.net/awnqm/284/ 这不工作是小提琴,我有一个简单的数据列表和输入(使用数据列表)。 为什么ng-hide选项标签不起作用。伍隐藏在数据列表角

回答

4

ngHide不适用于选项。你需要使用ngIf。但是,它可以从Angular 1.1.5(Angular 1.1.5 introduced the ngIf directive)获得。因此,更新您的Angular版本并使用ngIf来解决问题。见

<body ng-app> 
<datalist id="dataList"> 
    <select id="select"> 
    <option ng-repeat="val in temp" ng-if="false" >{{val}}</option> 
    </select> 
</datalist>        
<input list="dataList" ng-model="fromLocation" /> 
</body> 

http://jsfiddle.net/Gosha_Fighten/awnqm/288/

ngHide简单套用display: none CSS到不用于选项的作用的元素。例如,[IE11, Win7] "display: none" on OPTION tag is ignored。 ngIf根本不呈现元素。

+0

非常感谢您的帮助。我对ng-f有一些想法,但不知道版本问题。谢谢 –

+0

JFYI,我已经更新了我的答案,以提供更多关于它如何工作的信息。 –