我正在使用NG2-为可用的日期和日期到期的数据报警器。我想知道是否有人知道如何设置初始值。日期选择器的所有功能都正常,我只想让dateAvaliable成为今天的日期,然后dateExpires成为2099-12-31。
<label>Date Avaliable:</label>
<div>
<ng2-datepicker name="dateAvaliable" [(ngModel)]="dateAvaliable" [ngModelOPtions]="{standalone: true}"> </ng2-datepicker>
</div>
<label>Date Expires:</label>
<div>
<ng2-datepicker name="dateExpires" [(ngModel)]="dateExpires" [ngModelOPtions]="{standalone: true}"> </ng2-datepicker>
</div>组件
private today = new Date();
private dd: any = this.today.getDate();
private mm: any = this.today.getMonth() +1;
private year: any = this.today.getFullYear();
public sop: Sop;
public dateExpires: any;
public dateAvaliable: any;
ngOnInit() {
if (this.dd<10) {
this.dd ='0'+this.dd;
}
if(this.mm<10){
this.mm='0'+this.mm;
}
this.sop = {
description: "",
country: [this.countrys[4].value],
storeType: [this.storeTypes[4].value],
scoType: [this.scoTypes[6].value],
audience: [this.audiences[2].value],
sopType: [this.sopTypes[2].value],
dateAvaliable: this.year +'-'+this.mm+'-'+this.dd,
dateExpires: "2099-12-31"
}
}这是我的界面
export interface Sop {
description: String;
country?: String[];
storeType?: String[];
scoType?: String[];
audience?: String[];
sopType?: String[];
dateAvaliable: any;
dateExpires: any;
}发布于 2017-04-14 09:53:21
您还可以使用如下所示:
从‘NG2-Datepicker’导入{ DatePickerOptions};
发布于 2017-01-05 23:25:41
您需要使用[options]来设置初始值
<ng2-datepicker name="dateExpires" [(ngModel)]="dateExpires" [options]="{maxDate: dateExpires}"></ng2-datepicker>初始化选项
ngOnInit() {
this.dateExpires = moment("2099-12-31");
}https://stackoverflow.com/questions/41495020
复制相似问题