我在我的项目中使用 ng2-bootstrap 日期选择器。我想在单击日历图标时显示日期选择器。并且还想在选择日期时隐藏它。
<label>Date:</label>
<div class="datepickerDiv">
<input type="text" value="{{ getDate() | date:'dd-MMMM-yyyy' }}" class="datepicker">
<span class="cal-icon" (click)="open()"><i class="fa fa-calendar-check-o" aria-hidden="true"></i></span>
<span class="clearDate" (click)="clearDate()"><i class="fa fa-times-circle" aria-hidden="true"></i></span>
<ul class="datepicker-ul" role="menu" *ngIf="opened">
<datepicker [(ngModel)]="Date" [minDate]="minDate" [showWeeks]="false"></datepicker>
</ul>
</div>
我的组件如下
private opened:boolean = false;
public open():void {
this.opened = !this.opened;
}
public getDate():number {
return this.Date && this.Date.getTime() || new Date().getTime();
}
private clearDate() {
this.Date = null;
}
现在的问题是只有当我再次单击该图标时它才会关闭。