2016-04-13 42 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,我已經更新了我的答案,以提供更多關於它如何工作的信息。 –