0

从 ng-bootstrap(此处)的“弹出窗口中的日期选择器”示例开始,我尝试添加另一个用于日期导航的按钮;但是,我无法让它工作。

任何想法,将不胜感激。

<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>
4

1 回答 1

0

在切换后使用 navigateTo。您可以使用辅助变量“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>
于 2018-11-07T21:57:59.297 回答