【问题标题】:Bootstrap pop-up calendar in Angular 4Angular 4中的引导弹出日历
【发布时间】:2017-11-04 04:39:07
【问题描述】:

我正在使用 Bootstrap 弹出日历,我可以选择不同的日期。我想在单击某个日期时导入特定数据。我已经有了可以导入数据的表格,我只想使用选择的不同日期更新条目。

我应该如何处理这个问题?

日历

<span>
      <form class="form-inline">
          <button (click)="myEvent($event)">Test</button>
          <span style='margin-right:1.25em; display:inline-block;'>&nbsp;</span>
    <div class="form-group">
      <div class="input-group">
        <input class="form-control"
               placeholder="yyyy-mm-dd"
               name="dp"
               [(ngModel)]="model"
               ngbDatepicker
               #d="ngbDatepicker">
        <button class="input-group-addon"
                (click)="d.toggle()"
                type="button">
              <img src="img/calendar-icon.svg" style="width: 0.5rem; height: 0.5rem; cursor: pointer;"/>
            </button>
      </div>
    </div>
    </form>
    </span>

【问题讨论】:

  • 使用响应式表单而不是模板驱动表单会更容易
  • 为什么要在这个简单的案例中使用反应形式?对于他面临的问题,我认为模板驱动没有任何好处
  • 实用提示:如果您收到关于您的问题的反馈(例如离题或重复),或者如果提问方式可以改进(例如不鼓励紧急治疗请求),则无需删除这个问题。只需根据需要编辑问题,并根据需要回复 cmets。大多数反馈——即使它很重要——都是为了提供帮助。

标签: angular calendar angular-ui-bootstrap


【解决方案1】:

如果我理解正确,您的问题是,一旦选定的日期是某个特定日期,您就会尝试获取一些数据(触发一些操作)。我说的对吗?

如果是这样的话,你只需要控制输入日期的模型发生变化时触发的事件,你该怎么做呢?使用 ngModel 和 ngModelChange。

示例:

input class="form-control"
               placeholder="yyyy-mm-dd"
               name="dp"
               [ngModel]="model"
               (ngModelChange)="onChange($event)"
               ngbDatepicker
               #d="ngbDatepicker">

然后在打字稿文件中,创建一个方法来处理每次模型更新时:

onChange(date) {
   this.model = date; // This is what [()] banana box does automatically
   checkIfDateIsWhatIAmExpecting(date) // call the method to check if is the date and if so, load/fetch/do whatever you need
}

【讨论】:

  • 您好劳拉,感谢您的帮助。我应该在某处声明模型吗?我收到一个错误,类型上不存在属性“模型”。
  • 是的,您需要在文件中声明属性,只需使用 model: any;我很高兴在函数和属性声明中明确定义类型,但我不确定 datepicker 给你什么类型(我认为是字符串)
猜你喜欢
  • 1970-01-01
  • 2017-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多