从ng-bootstrap(here)的“弹出窗口中的日期选择器”示例开始,我尝试添加另一个用于日期导航的按钮;但是,我无法使它正常工作。
任何想法都会受到赞赏。
<form class="form-inline">
<div class="form-group">
<div class="input-group">
<input class="form-control" placeholder="yyyy-mm-dd"
name="dp" [(ngModel)]="model" ngbDatepicker #d="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar" (click)="d.toggle()" type="button"></button>
**<button class="btn btn-outline-secondary calendar" (click)="d.navigateTo()" type="button">Nav to this month</button>**
</div>
</div>
</div>
</form>
答案 0 :(得分:0)
在切换后立即使用navigationTo。您可以使用辅助变量“ auxiliar” 像这样:
<button class="btn btn-outline-secondary"
(click)="auxiliar={year:2020,month:3}" type="button">Nav to 2020/03</button>
<div class="input-group">
<input class="form-control" placeholder="yyyy-mm-dd"
name="dp" [(ngModel)]="model" ngbDatepicker #d="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar"
(click)="d.toggle();d.navigateTo(
{year:!model?auxiliar.year:model.year,
month:!model?auxiliar.month:model.month})"
type="button">
</button>
</div>
</div>