Reputation: 14142
I am using the Angular Material 2 Datepicker with Angular 4.x - when I select a date it should emit a function when the datepicker closes (it closes when a date is selected). I basically want to be able to select a date and not have the datepicker close (it should remain on the screen and highlight the selected day)
This is based on the following code which works fine on stackblitz - but not within my own app for some reason? https://stackblitz.com/edit/angular-ysspzm-ckkrbd
-NOTE- The stackblitz code is some generic code I came across and isn't the same as my code below (although it is almost identical)
// component
@Component({
selector: 'app-datepicker',
templateUrl: './datepicker.component.html',
styleUrls: ['./datepicker.component.scss'],
})
export class DatepickerComponent {
@ViewChild('keepOpen') _input: ElementRef;
_openCalendar(picker: MatDatepicker<Date>) {
picker.open();
console.log('here1'); // i see this in the console
}
_openCalendarClosed(picker: MatDatepicker<Date>) {
picker.open();
console.log('here2'); // never ever see this in the console log??
}
}
// html
<input
matInput
[matDatepicker]="picker"
placeholder="Choose a date"
(click)="_openCalendar(picker)"
#keepOpen>
<mat-datepicker-toggle
matSuffix
[for]="picker">
</mat-datepicker-toggle>
<mat-datepicker
#picker
class="fixed-open"
opened="true"
(closed)="_openCalendarClosed(picker)">
</mat-datepicker>
Upvotes: 1
Views: 3800
Reputation: 2650
Looks like material 5.0.0-rc.1 is the version where the datepicker component recieved the ability to output the closed
event. You mentioned that you're using material 2.0.0-beta.12, so an update would be needed in order to support this behavior.
Upvotes: 3