我使用ng2-datepicker来获取可用的日期和日期 . 我想知道是否有人知道如何设置初始值 . 使用日期选择器的所有工作,我只想 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;
}
2 回答
你也可以使用如下:
import from 'ng2-datepicker';
然后声明一个变量: public dateOptions: DateOptions;
并在ngOnit中初始化它:ngOnInit(){
您需要使用
[options
]来设置初始值初始化选项