我正在学习angularjs并使用angularjs材料的datepicker组件进行日期控制,但它不起作用,我使用的材料与material.angularjs.org中的相同,但是我的控件没有显示请帮忙。 我的html页面是DatePicker.html:
<!DOCTYPE html>
<html ng-app="datepickerBasicUsage">
<head>
<title></title>
<link href="angular-material.min.css" rel="stylesheet" />
<script src="angular.min.js"></script>
<script src="angular-animate.min.js"></script>
<script src="angular-aria.min.js"></script>
<script src="angular-material.min.js"></script>
<script src="myapp.js"></script>
</head>
<body>
<div ng-controller="AppCtrl" style='padding: 40px;'>
<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" placeholder="Enter date" disabled></md-datepicker>
<h4>Date-picker with min date and max date</h4>
<md-datepicker ng-model="myDate" placeholder="Enter date" md-min-date="minDate" md-max-date="maxDate"></md-datepicker>
</md-content>
</div>
</body>
</html>
myapp.js
angular.module('datepickerBasicUsage', ['ngMaterial'])
.controller('AppCtrl', function($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());
});
以上是我从网站的文档中获得的代码。 但它不起作用,我做错了什么。请帮忙。
答案 0 :(得分:4)
我认为您的导入确实有问题,我将代码放入plunker
<div ng-controller="AppCtrl" style='padding: 40px;'>
<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" placeholder="Enter date" disabled></md-datepicker>
<h4>Date-picker with min date and max date</h4>
<md-datepicker ng-model="myDate" placeholder="Enter date"
md-min-date="minDate" md-max-date="maxDate"></md-datepicker>
</md-content>
</div>
它工作正常吗?请检查你的进口!
答案 1 :(得分:0)
您需要在app.module.ts
中提及以下内容import { MdDatepickerModule } from '@angular/material';
import { MdNativeDateModule } from '@angular/material';
这是在进口数组
imports [
MdDatepickerModule,
MdNativeDateModule
]