greatCodeIdeas / md-date-range-picker

Angular Material Date Range Picker Service/Directive
MIT License
62 stars 40 forks source link

When we add custom templates, how can we get that selected by default ? #37

Closed vishnu-vv closed 6 years ago

vishnu-vv commented 6 years ago
$rootScope.mdCustomTemplates = [
  {
    name: 'Last 30 Days',
    dateStart: new Date(tempDate),
    dateEnd : new Date()
  }
];

$rootScope.selectedRange = {
  selectedTemplate: 'TW',
  selectedTemplateName: 'Last 30 Days',
  dateStart: new Date(tempDate),
  dateEnd: new Date(),
  showTemplate: true,
  fullscreen: true,
  firstDayOfWeek: 0,
  customTemplates: $rootScope.mdCustomTemplates,
  isDisabledDate: $rootScope.isFutureDate
};

I want Last 30 Days to be selected by default. Something like this:

$rootScope.selectedRange = {
  selectedTemplate: 'L30D',
  selectedTemplateName: 'Last 30 Days',
  dateStart: new Date(tempDate),
  dateEnd: new Date(),
  showTemplate: true,
  fullscreen: true,
  firstDayOfWeek: 0,
  customTemplates: $rootScope.mdCustomTemplates,
  isDisabledDate: $rootScope.isFutureDate
};
roelbarreto commented 6 years ago

At some point the dateStart and dateEnd are filled after any digest event

$rootScope.selectedRange = {
      selectedTemplate: 'L30D',
      selectedTemplateName: 'Last 30 Days',
}
// Option 1 wait for any diggest
$timeout(function(){
  // You can do something with the binded value here
   console.log($rootScope.selectedRange.dateStart, $rootScope.selectedRange.dateEnd);
});

or get the mdOnSelect event

<md-date-range md-on-select="handleOnSelect()" ng-model="selectedRange"></md-date-range>
$rootScope.handleOnSelect = function(){
  // do something with here to retrieve model computed values
  console.log( $rootScope.selectedRange)
}

Hope this helps

vishnu-vv commented 6 years ago

image

See this attachment. @ipiz

roelbarreto commented 6 years ago

Sorry I dint understand the first question, I'll make a fix for this one

vishnu-vv commented 6 years ago

@ipiz That was awesome 👍