最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to initialize the date value of Angular Material md-datepicker to any specified date - Stack Overflow

programmeradmin0浏览0评论

In Angular Material md-datepicker, when I click on date picker it sets the system's current date as today's date. We notice that today's date is circled in the date picker's calendar. I want to know if there is a way to set any given date as today's date. Please refer this image. md-datepicker's calender (today's date highlighted in Yellow)

So, in my case, if I set today's date as 2nd April 2017, the datepicker should set this as today's date and circle this date on the calendar

In Angular Material md-datepicker, when I click on date picker it sets the system's current date as today's date. We notice that today's date is circled in the date picker's calendar. I want to know if there is a way to set any given date as today's date. Please refer this image. md-datepicker's calender (today's date highlighted in Yellow)

So, in my case, if I set today's date as 2nd April 2017, the datepicker should set this as today's date and circle this date on the calendar

Share Improve this question asked Mar 4, 2017 at 9:53 Sameer ShaikSameer Shaik 1671 gold badge3 silver badges12 bronze badges 1
  • You can use <md-datepicker ng-model="ctrl.myDate" md-placeholder="Enter date"></md-datepicker> and in you controller this.myDate = new Date('2017-04-17T03:24:00'); – Dhananjay Sakhare Commented Mar 4, 2017 at 10:31
Add a ment  | 

1 Answer 1

Reset to default 3

HTML

<md-content ng-controller="AppCtrl as ctrl" layout-padding="" ng-cloak="" class="datepickerdemoBasicUsage" ng-app="MyApp">
  <div layout-gt-xs="row">
    <div flex-gt-xs="">
      <h4>Standard date-picker</h4>
      <md-datepicker ng-model="ctrl.myDate" md-placeholder="Enter date"></md-datepicker>
    </div>
</md-content>

JS

angular.module('MyApp',['ngMaterial', 'ngMessages', 'material.svgAssetsCache']).controller('AppCtrl', function() {
  this.myDate = new Date('2017-04-17T03:24:00');
  this.isOpen = false;
});

this.myDate = new Date('2017-04-17T03:24:00');

You can set your own date here. In your case you wanted 2nd April 2017 as default date in datetime picker then you should write

this.myDate = new Date('2017-04-01T03:24:00');

Live Demo

I referred Angular Material website for this

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论