bleenco / ng2-datepicker

Angular2 Datepicker Component
http://ng2-datepicker.jankuri.com
MIT License
311 stars 236 forks source link

Default to Next month #211

Open dotnet0509 opened 7 years ago

dotnet0509 commented 7 years ago

Hi, I would like to set the initial month to next month, i.e. if it is March, I would like to display April as soon as I open the datepicker.

Thanks

JordanWCotton commented 7 years ago

Hey,

Not sure if this what you are looking for, but the options object allows you to pass an initialDate with a value of Date(). All you would have to do is create a variable that had the current date + 1 month, and pass that to the options object. You could have a function perform this, and maybe have ngOnInit () call that function so that it is performed right off the bat. A very crude, quick example would be something like:

currentYear = new Date().getFullYear();
currentDay = new Date().getDate();
nextMonth = new Date().getMonth() + 1;
nextMonthDate = new Date(this.currentYear, this.nextMonth, this.currentDay);

Then you would assign initialDate to this.nextMonthDate in the passed options object in the component constructor. Every time you open the datepicker it will default to the current day but of next month, and of the current year.

Hope this helps.