angular-material-components icon indicating copy to clipboard operation
angular-material-components copied to clipboard

No daySelected event emit

Open samnangcattor opened this issue 3 years ago • 1 comments

No daySelected, I have check on https://github.com/h2qutc/angular-material-components/blob/f147c1c9645167fb170bbca4aa9d91f757c2bb5a/projects/datetime-picker/src/lib/datetime-picker.component.ts It just has monthSelected & yearSelectd

samnangcattor avatar Mar 11 '21 03:03 samnangcattor

@samnangcattor here you go some workaround:

` @ViewChild('picker', { static: true }) datepicker!: NgxMatDatetimePicker; defaultOptions = { templateOptions: { datepickerOptions: { startView: 'month', datepickerTogglePosition: 'suffix', dateInput: () => {}, dateChange: () => {}, monthSelected: () => {}, yearSelected: () => {} } } };

private _sub$: Subject = new Subject();

detectChanges() { this.options['detectChanges']?.(this.field); }

ngOnDestroy() { super.ngOnDestroy(); }

ngAfterViewInit() { super.ngAfterViewInit(); this.to[this.to.datepickerOptions.datepickerTogglePosition] = this.datepickerToggle; this.dayClickHandler(); }

dayClickHandler() { const onCellClick = (event: PointerEvent) => { if ( (event.target as HTMLElement).classList.contains( 'mat-calendar-body-cell-content' ) ) { this.to?.datepickerOptions?.daySelected( this.field, this.datepicker._selected ); console.log(this.datepicker); } }; let popupRef: HTMLElement; this.datepicker.openedStream.pipe(takeUntil(this._sub$)).subscribe(() => { popupRef = this.datepicker._popupRef.overlayElement; popupRef.addEventListener('click', onCellClick); }); this.datepicker.closedStream.pipe(takeUntil(this._sub$)).subscribe(() => { popupRef?.removeEventListener('click', onCellClick); }); } `

mrtmeeseeks avatar Aug 24 '21 08:08 mrtmeeseeks