Selects

优质
小牛编辑
141浏览
2023-12-01

md-select ,一个Angular指令用于显示选择框,由ng-model限定。

属性 - md-radio-group

下表列出了md-radio-group的不同属性的参数和描述。

Sr.No参数和描述
1

* ng-model

该模型!

2

multiple

是否是多重的。

3

md-on-close

选择关闭时要评估的表达式。

4

placeholder

占位符提示文本。

5baria-label

可访问性的可选标签。 仅在没有占位符或显式标签的情况下才有必要。

6

md-container-class

要应用于.md-select-menu-container元素的类列表(用于自定义样式)。

例子 (Example)

以下示例展示了使用选择框的md-select showcase使用。

am_selects.htm

<html lang = "en">
   <head>
      <link rel = "stylesheet"
         href = "https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
      <link rel = "stylesheet" href = "https://fonts.googleapis.com/icon?family=Material+Icons">
      <script language = "javascript">
         angular
            .module('firstApplication', ['ngMaterial'])
            .controller('selectController', selectController);
         function selectController ($scope) {
            $scope.users = [
               { id: 1, name: 'Mahesh' },
               { id: 2, name: 'Ramesh' },
               { id: 3, name: 'Sohan' }
            ];
            $scope.selectedUser = { id: 2, name: 'Ramesh' };
            $scope.drinks = [
               { category: 'hard', name: 'Beer' },
               { category: 'hard', name: 'Rum' },
               { category: 'hard', name: 'Vodka' },
               { category: 'hard', name: 'Whiski' },        
               { category: 'soft', name: 'Coke' },
               { category: 'soft', name: 'Pepsi' },
               { category: 'soft', name: 'Pulp Maid' },
               { category: 'soft', name: 'Real Juice' }
            ];
         }	  
      </script>      
   </head>
   <body ng-app = "firstApplication"> 
      <div id = "selectContainer" ng-controller = "selectController as ctrl"
         layout = "row" ng-cloak>
         <md-input-container>
            <label>User</label>
            <md-select ng-model = "selectedUser">
               <md-option ng-value = "user"
                  ng-repeat = "user in users">{{ user.name }}</md-option>
            </md-select>
         </md-input-container>
         <md-input-container>
            <label>Drinks</label>
            <md-select ng-model = "drink">
               <md-optgroup label = "Hard Drinks">
                  <md-option ng-value = "drink.name"
                     ng-repeat = "drink in drinks | filter: {category: 'hard' }">
                     {{drink.name}}</md-option>
               </md-optgroup>
               <md-optgroup label = "Soft Drinks">
                  <md-option ng-value = "drink.name"
                     ng-repeat = "drink in drinks | filter: {category: 'soft' }">
                     {{drink.name}}</md-option>
               </md-optgroup>
            </md-select>
         </md-input-container>
      </div>
   </body>
</html>