简体   繁体   English

角度选择框选项:已选中

[英]angular select box option:selected

I have a search form where you can search for a hotel. 我有一个搜索表,您可以在其中搜索酒店。 It also asks for the number of Adults as a select box (I want it to default to 2). 它还要求输入“成人数”作为选择框(我希望将其默认设置为2)。

To maintain state I have the search results saving as sessionStorage. 为了保持状态,我将搜索结果另存为sessionStorage。 I then want to pick this up and have the selected value of the number of adults that was set in the session. 然后,我要进行选择,并获得会话中设置的成人数量的选定值。

Can anyone help? 有人可以帮忙吗? Can't find this anywhere. 在任何地方都找不到。

If understand correctly for your select you will need to do something like this: 如果正确理解您的选择,则需要执行以下操作:

<select ng-options="item as item.label for item in items track by item.id" ng-model="selected"></select>

In your angular controller you can set $scope.selected to value 2 so that will be the default. 在角度控制器中,您可以将$ scope.selected设置为值2,以便将其作为默认值。 You can read more here 你可以在这里阅读更多

Please let me know if you have anymore questions. 如果您还有其他问题,请告诉我。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM