繁体   English   中英

使用angular js创建一个下拉菜单

[英]Creating a drop-down menu with angular js

我想获得各种操作系统的下拉列表,供用户选择。 到目前为止,这是我的代码

<form id="main">
    <table>
        <tr>
            <td class="display_bold"><label for="name">VM Name:</label></td>
        </tr>
        <tr>
            <td class="display"><input type="text" ng-model="virMachine.vmName" size="40"></td>
        </tr>
        <tr>
            <td class="display_bold" ><label  for="name">OS Type:</label></td>
        </tr>
        <tr>
            <td class="display"><input type="text" ng-model="virMachine.osVersion" size="40"></td>
        </tr>
    </table>

这是我要创建下拉菜单的OS列表。

$scope.operatingsystems = ["Ubuntu-16", "Centos 7", "Wimdows"];

我该怎么做? 我知道我可能已经将输入类型从文本更改为其他内容,但不确定是什么。

只要你能做到

<select ng-model="osType">
   <option ng-repeat="os in operatingsystems">{{os }}</option>
</select>

演示

 angular.module('myApp',[]).controller('studentController', function($scope){ $scope.operatingsystems = ["Ubuntu-16", "Centos 7", "Wimdows"]; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="studentController"> <table> <tr> <td class="display_bold"><label for="name">VM Name:</label></td> </tr> <tr> <td class="display"><input type="text" ng-model="virMachine.vmName" size="40"></td> </tr> <tr> <td class="display_bold"><label for="name">OS Type:</label></td> </tr> <tr> <td class="display"><select ng-model="osType"> <option ng-repeat="os in operatingsystems">{{os }}</option> </select></td> </tr> </table> </div> </body> 

Angular.js中的下拉列表可能如下所示:

<select ng-model="osType">
    <option value=" ">Choose OS</option>
    <option ng-repeat="o in operatingsystems">{{o}}</option>
</select>

暂无
暂无

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

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