我正在使用Angular 4创建一个包含开始时间和结束时间的表单,使用两个ngb-timepicker。当我将模型设置为它们时,第一个实例化第二个的值。有关如何单独实例化它们的任何想法? 我的HTML看起来像这样:
<ngb-timepicker [(ngModel)]="time1"></ngb-timepicker>
<ngb-timepicker [(ngModel)]="time2"></ngb-timepicker>
我的组件:
import {Component} from '@angular/core';
@Component({
selector: 'schedule-form',
templateUrl: './schedule-form.component.html'
})
export class NgbdTimepickerBasic {
time1 = {hour: startDateH, minute: startDateM};
time2 = {hour: endDateH, minute: endDateM};
}
结果是time1将显示time2,因此只有time2是正确的。
答案 0 :(得分:0)
您需要NgbTimeStruct
格式化ngb-timepicker
知道的日期
import {Component} from '@angular/core';
import {NgbTimeStruct} from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'schedule-form',
templateUrl: './schedule-form.component.html'
})
export class NgbdTimepickerBasic {
//declaration
time1: NgbTimeStruct;
time2: NgbTimeStruct;
ngOnInit() {
//get your start and end time and assign it to below
this.time1 = {hour: 13, minute: 30, second: 0};
this.time2 = {hour: 16, minute: 15, second: 0};
}
}