Has anyone figured out how to set an initial value for the ng2-datepicker when using it for available date and date expires? I want the initial value of dateAvailable
to be today's date and the initial value of dateExpires
to be 2099-12-31
.
<label>Date Available:</label>
<div>
<ng2-datepicker name="dateAvailable" [(ngModel)]="dateAvailable" [ngModelOptions]="{standalone: true}"> </ng2-datepicker>
</div>
<label>Date Expires:</label>
<div>
<ng2-datepicker name="dateExpires" [(ngModel)]="dateExpires" [ngModelOptions]="{standalone: true}"> </ng2-datepicker>
</div>
Component
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 dateAvailable: 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],
dateAvailable: this.year +'-'+this.mm+'-'+this.dd,
dateExpires: "2099-12-31"
}
}
Interface
export interface Sop {
description: String;
country?: String[];
storeType?: String[];
scoType?: String[];
audience?: String[];
sopType?: String[];
dateAvailable: any;
dateExpires: any;
}