Closed RonRofe closed 4 years ago
There is an example in wiki pages. Example app example.
Both of those examples use javascript date object to initialize the date. It is also possible to initialize with the IMyDate object.
Example to initialize with IMyDate object.
<input class="form-control" placeholder="Select a date" angular-mydatepicker
name="myDate" formControlName="myDate" [options]="myOptions"
#dp="angular-mydatepicker"/>
ngOnInit() {
// Initialize to yesterday date
let d: Date = new Date();
d.setDate(d.getDate() - 1);
let model: IMyDateModel = {isRange: false, singleDate: {
date: { year: d.getFullYear(), month: d.getMonth() + 1, day: d.getDate() }
}};
this.myForm = this.formBuilder.group({
myDate: [model, Validators.required]
// other controls are here...
});
}
How can I put a default value on reactive forms when the form initializes ?