角度材质 - 输入


md -input-container是一个 Angular 指令,是一个包含任何<input><textarea>元素作为子元素的容器组件。它还支持使用标准 ng-messages 指令进行错误处理,并使用 ngEnter/ngLeave 事件或 ngShow/ngHide 事件对消息进行动画处理。

属性

下表列出了md-input-container的参数和不同属性的说明。

先生编号 参数及说明
1

md-最大长度

此输入中允许的最大字符数。如果指定了此项,字符计数器将显示在输入下方。md-maxlength 的目的是显示最大长度计数器文本。如果您不需要计数器文本并且只需要“普通”验证,则可以使用“简单”ng-maxlength 或 maxlength 属性。

2

咏叹调标签

当没有标签时,需要 Aria-label。如果标签不存在,控制台中将记录一条警告消息。

3

占位符

当标签不存在时使用 aria-label 的另一种方法。占位符文本将复制到 aria-label 属性。

4

md-无自动增长

当存在时,文本区域不会自动增长。

5

md 检测隐藏

如果存在,文本区域在隐藏后显示时将适当调整大小。出于性能原因,默认情况下此功能处于关闭状态,因为它保证每个摘要周期都会回流。

例子

以下示例显示了 md-input-container 指令的使用以及输入的使用。

am_inputs.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">
      <style>
        
      </style>
      <script language = "javascript">
         angular
            .module('firstApplication', ['ngMaterial'])
            .controller('inputController', inputController);

         function inputController ($scope) {
            $scope.project = {
               comments: 'Comments',    
            };
         }                 
      </script>     	  
   </head>
   
   <body ng-app = "firstApplication"> 
      <div id = "inputContainer" class = "inputDemo"
         ng-controller = "inputController as ctrl" ng-cloak>
         <md-content layout-padding>
            <form name = "projectForm">
               
               <md-input-container class = "md-block">
                  <label>User Name</label>
                  <input required name = "userName" ng-model = "project.userName">
                  <div ng-messages = "projectForm.userName.$error">
                     <div ng-message = "required">This is required.</div>
                  </div>
               </md-input-container>
               
               <md-input-container class = "md-block">
                  <label>Email</label>
                  <input required type = "email" name = "userEmail"
                     ng-model = "project.userEmail"
                     minlength = "10" maxlength = "100" ng-pattern = "/^.+@.+\..+$/" />
                  <div ng-messages = "projectForm.userEmail.$error" role = "alert">
                     <div ng-message-exp = "['required', 'minlength', 'maxlength',
                        'pattern']">
                        Your email must be between 10 and 100 characters long and should
                        be a valid email address.
                     </div>
                  </div>
               </md-input-container>
               
               <md-input-container class = "md-block">
                  <label>Comments</label>
                  <input md-maxlength = "300" required name = "comments"
                     ng-model = "project.comments">
                  <div ng-messages = "projectForm.comments.$error">
                     <div ng-message = "required">This is required.</div>
                     <div ng-message = "md-maxlength">The comments has to be less
                        than 300 characters long.</div>
                  </div>
               </md-input-container>
               
            </form>
         </md-content>
      </div>
   </body>
</html>

结果

验证结果。