javascript - How do I set the `startAt` date when using Angular Material Calendar? - Stack Overflow

I'm using material2 v2.0.0-beta.10 as well as Angular v4 and having issues when using md-calendar

I'm using material2 v2.0.0-beta.10 as well as Angular v4 and having issues when using md-calendar ponent. My problem is that I'm unable to set the startAt date to anything.

I set start date to yesterday as follows:

  this.startAt = new Date();
  this.startAt = this.startAt.setDate(this.startDate - 1);

Here is a Plunkr of attempting to set the startAt date to yesterday.

What am I missing?

I'm using material2 v2.0.0-beta.10 as well as Angular v4 and having issues when using md-calendar ponent. My problem is that I'm unable to set the startAt date to anything.

I set start date to yesterday as follows:

  this.startAt = new Date();
  this.startAt = this.startAt.setDate(this.startDate - 1);

Here is a Plunkr of attempting to set the startAt date to yesterday.

What am I missing?

Share Improve this question edited Dec 10, 2020 at 14:05 Vega 28.7k28 gold badges120 silver badges145 bronze badges asked Sep 13, 2017 at 11:46 onetwothreeonetwothree 6921 gold badge11 silver badges20 bronze badges 2
  • Just update everything to v4? Try to keep up in the end it will limit you alot. – Swoox Commented Sep 13, 2017 at 12:13
  • @Swoox I am using Angular v4 and material 2 v2.0.0-beta.10. Updated the question to reflect this fact. – onetwothree Commented Sep 13, 2017 at 12:18
Add a ment  | 

1 Answer 1

Reset to default 7

The start date accepts the following format:

startDate = new Date(1990, 0, 1);

Citing from the docs:

The month or year that the calendar opens to is determined by first checking if any date is currently selected, if so it will open to the month or year containing that date. Otherwise it will open to the month or year containing today's date. This behavior can be overridden by using the startAt property of md-datepicker. In this case the calendar will open to the month or year containing the startAt date.

So if you wish, say, to set the starting date to the next month, the following code should work:

let today = new Date();
let month = today.getMonth() + 1; //next month
let year = today.getUTCFullYear();
let day = today.getDay();

this.startAt = new Date(year, month, day);

DEMO

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744189553a4562367.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信