2017-06-15 71 views
0

我希望獲得各種操作系統的下拉列表供用戶選擇。這是我的代碼到目前爲止創建一個帶有角度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> 

這是我想創建一個下拉菜單的操作系統列表。

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

我該怎麼做?我知道我可能會將輸入類型從文本更改爲其他內容,但不知道是什麼。

+1

你想在桌子內部展示? – Sajeetharan

+0

是的。這部分 user3078335

回答

1

只要你能做到這一點,

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

DEMO

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>

+0

非常感謝! – user3078335

+0

不客氣 – Sajeetharan

+2

只是改變ng型 – Sajeetharan

0

在Angular.js一個下拉可能是這個樣子:

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