- Angular Material 教程
- Angular Material - 首页
- Angular Material - 概述
- 环境搭建
- Angular Material - 自动完成
- Angular Material - 底部菜单
- Angular Material - 卡片
- Angular Material - 组件
- Angular Material - 布局
- Angular Material - 输入控件
- Angular Material - 图标
- Angular Material - 网格
- Angular Material - 侧边导航栏
- Angular Material - 浮动操作按钮 (FAB) 速度拨号
- Angular Material - 副标题
- Angular Material - 滑动
- Angular Material - 开关
- Angular Material - 主题
- Angular Material - 提示信息
- Angular Material - 排版
- Angular Material - 虚拟滚动
- Angular Material - 白框
- Angular Material 有用资源
- Angular Material - 快速指南
- Angular Material - 有用资源
- Angular Material - 讨论
Angular Material - 输入控件
md-input-container 是一个 Angular 指令,它是一个容器组件,包含任何<input> 或 <textarea> 元素作为子元素。它还支持使用标准 ng-messages 指令进行错误处理,并使用 ngEnter/ngLeave 事件或 ngShow/ngHide 事件为消息添加动画。
属性
下表列出了md-input-container的不同属性的参数和描述。
序号 | 参数和描述 |
---|---|
1 | md-maxlength 此输入允许的最大字符数。如果指定了此属性,则输入下方会显示一个字符计数器。md-maxlength 的目的是显示最大长度计数器文本。如果您不想要计数器文本,而只需要“简单”验证,可以使用“simple” ng-maxlength 或 maxlength 属性。 |
2 | aria-label 如果没有标签,则需要 aria-label。如果没有标签,控制台将记录警告消息。 |
3 | placeholder 当没有标签时,可以使用 aria-label 的替代方法。占位符文本将复制到 aria-label 属性。 |
4 | md-no-autogrow 存在此属性时,文本区域不会自动增长。 |
5 | md-detect-hidden 存在此属性时,文本区域在隐藏后显示时将被正确调整大小。出于性能原因,默认情况下此属性为关闭状态,因为它保证每次摘要周期都会重新计算布局。 |
示例
以下示例显示了 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>
结果
验证结果。
广告