At the moment, I am utilizing:
- ng-bootstrap 1.0.0-alpha.24
- angular/core 4.0.0
- bootstrap 4.0.0-alpha.6
I am curious to know if anyone has a solution on how to automatically close the datepicker when focus is lost or another datepicker is opened.
Additionally, I am wondering if it's feasible to close the datepicker in the component code using TypeScript.
If possible, could someone provide either a functional plunker or a code snippet?
My current setup looks like this:
<div class="input-group">
<input class="rect-border full-width"
placeholder="YYMMDD"
[(ngModel)]="selectedDate"
ngbDatepicker
#datePickerInput="ngbDatepicker"
(keydown.arrowup)="incrementDate()"
(keydown.arrowdown)="decrementDate()"
(ngModelChange)="validate('modelChanged')"
(blur)="validate(null)"
[disabled]="disabled"
[ngClass]="{'input-required': required, 'normal-color': valid, 'picker-disabled': disabled}">
<div class="input-group-addon rect-border"
(click)="disabled ? true : datePickerInput.toggle()"
[ngClass]="{'picker-button-disabled': disabled}">
<img src="assets/img/calendar-icon.svg" class="datpickerToggle"/>
</div>
</div>
Plunker: Check out the ng-bootstrap team demo here
I've been researching for quite some time and I'm fairly new to Angular and related technologies.
Thank you in advance for any assistance!
Update:
Potential Solution:
Several helpful solutions were shared. I also discovered that by using the NgbInputDatepicker class, I can successfully close the datepicker (previously I only used NgbDatepicker).
@ViewChild('datePickerInput') datePicker: NgbInputDatepicker;
this.datePicker.close();