简体   繁体   English

是否有一条指令允许选择一个选项后隐藏选择元素?

[英]Is there a directive which allows a select element to be hidden once an option has been selected?

Is there a directive which allows a select element to be hidden once an option has been selected? 是否有一条指令允许选择一个选项后隐藏选择元素?

I thought ng-blur was the way to go but it's not working for me. 我以为ng-blur是要走的路,但这对我不起作用。

select(ng-model="jawn", ng-options="range.value for range in ranges", 
ng-blur="hideMe", ng-if="jawnDropdown")

$scope.hideMe = function() {
    $scope.jawnDropdown = false;
}

您不能以模型为中心吗?

select(ng-model="jawn", ng-options="range.value for range in ranges", ng-if="!jawn")

You can use ng-show or ng-hide by binding it with the same model of the select box in this way : 您可以通过以下方式将ng-show或ng-hide与选择框的相同模型绑定在一起来使用:

<select ng-model="modelName" ng-show="modelName == '' || modelName == null" ng-change="functionName(modelName)">
    <option value="">Select name</option>
    <option ng-repeat="item in items" value="item.id">{{item.name}}</select>
</select>

This will show the select box only if the modelName 's value is null or empty & when you select something the condition in ng-show returns false & the select box will hide & you can use the ng-change directive to do any other operation on the select box's value. 仅当modelName的值为null或为空时,才会显示选择框;当您选择某些内容时,ng-show中的条件将返回false,并且选择框将隐藏,并且您可以使用ng-change指令执行任何其他操作在选择框的值上。

Hope this helps Cheers 希望这对干杯有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery:保存已选择的选择元素选项 - jQuery: Save a select element option that has been selected 根据选择选项元素中选择的选项显示隐藏的div元素 - Show hidden div element based on option selected in select option element 如何设置已在react js中选择的选择选项? - how to set select option which has already been selected in react js? jQuery - 用于检测是否已选择HTML select选项的事件处理程序 - jQuery - event handler to detect if HTML select option has been selected 选择一个选项后,打开HTML选择标签 - Open an HTML select tag after one option has been selected 选择从选择下拉菜单中的选项时出现的模态 - modal appearing when option from select dropdown has been selected 在Vue.js中,如何确保select元素连续选择了第一个选项,因为有条件地显示和隐藏了选项? - In Vue.js, how can I make sure a select element continuously has the first option selected as options are conditionally shown and hidden? 如何检测在“选择”下拉列表中选择了哪个选项 - How to detect which option has been chosen in “Select” dropdown list 查找在 getmdl-select 中选择了哪一行 - Finding which row has been selected in a getmdl-select 当从另一个 select 中选择了特定选项时,隐藏多个 select 中的选项 - Hide an option in a multiple select, when a specific option has been selected from another select
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM