- 教程
- 概述
- 环境设置(Environment Setup)
- 自动完成(Autocomplete)
- 角材料 - 底板(Bottom Sheet)
- Cards
- 小部件(Widgets)
- 布局(Layouts)
- 输入(Inputs)
- Icons
- Grids
- SideNav(SideNav)
- Fab 速拨号(Fab Speed Dial)
- 子头(Subheaders)
- Swipe
- 开关(Switches)
- 主题(Themes)
- 祝酒词(Toasts)
- 排版(Typography)
- 虚拟重复(Virtual Repeat)
- 白色框架(WhiteFrame)
- 有用的资源
- Buttons
- CheckBoxes
- Content
- DatePicker
- Dialogs
- Divider
- List
- Menu
- Menu Bar
- Progress Bars
- Radio Buttons
- Selects
- ListBox和ListCtrl(ListBox & ListCtrl)
- Sliders
- Tabs
- Toolbars
- Tooltips
- Chips
- Contact Chips
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
DatePicker
md-datepicker是一个Angular Directive,是一个输入控件,用于选择日期并支持ngMessages进行输入验证。
属性 (Attributes)
下表列出了md-datepicker的不同属性的参数和描述。
Sr.No | 参数和描述 |
---|---|
1 | * ng-model 该组件的模型需要一个JavaScript Date对象。 |
2 | ng-change 模型值更改时计算的表达式。 |
3 | md-min-date 表示最小日期(包括)的表达式。 |
4 | md-max-date 表达最大日期(包括)的表达式。 |
5 | md-date-filter 该函数需要一个日期并返回一个布尔值,并确定是否可以选择它。 |
6 | md-placeholder 日期输入占位符值。 |
7 | ng-disabled 这确定是否禁用了日期选择器。 |
8 | ng-required 这确定了datepicker是否需要值。 |
例子 (Example)
以下示例显示了md-datepicker指令的使用以及datepicker的用法。
am_datepicker.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>
<style>
.datepickerdemo md-content {
padding-bottom: 200px;
}
.datepickerdemo .validation-messages {
font-size: 11px;
color: darkred;
margin: 10px 0 0 25px;
}
</style>
<script language = "javascript">
angular
.module('firstApplication', ['ngMaterial','ngMessages'])
.controller('dateController', dateController);
function dateController ($scope) {
$scope.myDate = new Date();
$scope.minDate = new Date(
$scope.myDate.getFullYear(),
$scope.myDate.getMonth() - 2,
$scope.myDate.getDate());
$scope.maxDate = new Date(
$scope.myDate.getFullYear(),
$scope.myDate.getMonth() + 2,
$scope.myDate.getDate());
$scope.onlyWeekendsPredicate = function(date) {
var day = date.getDay();
return day === 0 || day === 6;
}
}
</script>
</head>
<body ng-app = "firstApplication">
<div class = "datepickerdemo" ng-controller = "dateController as ctrl"
layout = "column" ng-cloak>
<md-content>
<h4>Standard Date Picker</h4>
<md-datepicker
ng-model = "myDate"
md-placeholder = "Enter date"></md-datepicker>
<h4>Disabled Date Picker</h4>
<md-datepicker
ng-model = "myDate"
md-placeholder = "Enter date"
disabled></md-datepicker>
<h4>Date-picker with min and max dates</h4>
<md-datepicker
ng-model = "myDate"
md-placeholder = "Enter date"
md-min-date = "minDate"
md-max-date = "maxDate"></md-datepicker>
<h4>Date-picker with only selectable weekends</h4>
<md-datepicker
ng-model = "myDate"
md-placeholder = "Enter date"
md-date-filter = "onlyWeekendsPredicate"></md-datepicker>
<h4>Date-picker with only selectable weekends in a range</h4>
<md-datepicker
ng-model = "myDate"
md-placeholder = "Enter date"
md-min-date = "minDate"
md-max-date = "maxDate"
md-date-filter = "onlyWeekendsPredicate"></md-datepicker>
<h4>Date-picker with validation mesages</h4>
<form name = "myForm">
<md-datepicker
name = "dateField"
ng-model = "myDate"
md-placeholder = "Enter date"
required
md-min-date = "minDate"
md-max-date = "maxDate"
md-date-filter = "onlyWeekendsPredicate"></md-datepicker>
<div class = "validation-messages" ng-messages = "myForm.dateField.$error">
<div ng-message = "valid">The entered value is not a date!</div>
<div ng-message = "required">This date is required!</div>
<div ng-message = "mindate">Date is too early!</div>
<div ng-message = "maxdate">Date is too late!</div>
<div ng-message = "filtered">Only weekends are allowed!</div>
</div>
</form>
</md-content>
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论