嗨,我正在调查 ng-bootstrap datepicker。我查看了演示代码,并能够让它在我的应用程序中工作。
但是,如果我添加了超过 1 个 datepicker 输入标签,则只有一个在工作。下面是我创建的代码。我试图将#d 更改为#d1 和#d2(也更改toggle() 部分)并且页面吐出错误。
<div class="input-group">
<input class="form-control" placeholder="yyyy-mm-dd" name="dp" [(ngModel)]="newItem.EndTime" ngbDatepicker #d="ngbDatepicker" required>
<div class="input-group-addon" (click)="d.toggle()" >
<i class="fa fa-calendar" aria-hidden="true"></i>
</div>
</div>
<div class="input-group">
<input class="form-control" placeholder="yyyy-mm-dd" name="dp" [(ngModel)]="newItem.StartTime" ngbDatepicker #d="ngbDatepicker" required>
<div class="input-group-addon" (click)="d.toggle()" >
<i class="fa fa-calendar" aria-hidden="true"></i>
</div>
</div>
我还尝试用一个组件包装它,它允许我为不同的属性拥有多个 datepicker 实例。但是,它似乎没有将值传递回父组件。
new.campaign.html
<div class="row col-md-12 col-lg-12">
<div class="col-md-4 col-lg-4">
<label for="campaignStartTime">Start Time</label>
<datepicker-popup [(model)]="newItem.StartTime" (modelChange)="updateDate($event)" [required]="true" id="campaignStartTime"></datepicker-popup>
</div>
</div>
datepicker-popup.component.ts
import {Component, Input, Output, EventEmitter} from '@angular/core';
@Component({
selector: 'datepicker-popup',
templateUrl: 'app/campaign/datepicker-popup.html'
})
export class DatepickerPopupComponent {
@Input()
model:any;
@Input()
id:string;
@Input()
required:boolean=false;
@Output()
modelChange: EventEmitter<any> = new EventEmitter();
constructor(){ }
updateModel(){
let date = this.model;
date = '12/22/2016'
this.modelChange.emit(date);
}
}
datepicker-popup.html
<div class="input-group">
<input class="form-control" placeholder="yyyy-mm-dd" name="dp [(ngModel)]="model" (change)="updateModel()" ngbDatepicker #d="ngbDatepicker" required>
<div class="input-group-addon" (click)="d.toggle()" >
<i class="fa fa-calendar" aria-hidden="true"></i>
</div>
</div>
有人可以指出我解决问题的正确方向吗?