Currently building an app with angular material where we need a md-calendar component. We want to customize the button style and content and therefore don't use the normal md-datepicker. Problem is that when the md-calender is opened the scroll position is on 1933. The current date is correctly set.
How can I set the scroll position to be the current date?
The md-datepicker is using the md-calender as a subcomponent where the calendar is scrolled to the current date so should not be that hard to achieve.
The current work-around is to set the md-min-date property to a date close to the current date but this is not a good solution as it prohibits navigation to earlier dates.
Code pen example:
https://codepen.io/adam-wiman/pen/QKqRzd
<md-calendar>
Wll first I tried to upgrade to the latest
angular material v1.1.10
which was the solution I got when trying to answer thisSO Answer
, but doing this did not help solve your issue, although you can upgrade to latest, if you want to get rid of some bugs.Anyway, the problem is due to the
md-datepicker
not being properly intialized, there could be a number of reasons for that, my solution for your problem is to use the good old trusty,ng-if
to reinitialize themd-calendar
, doing so solves this issue.Note: Using
ng-if
will create an isolated scope, thus there is a possiblity of$scope
variables not updating properly, in these scenarios, you need to use the$parent
property to solve it, refer here.