I am really stuck here and I hope you could help me out.
I have the following problem: I have a reactive form with a date, using the ngBootstrap datePicker, and I am using the NgbDateNativeAdapter, so that my datepicker all work with native Dates. All I want is preset the value, like I would with any other form value.
In the template:
<form [formGroup]="myForm">
<input class="form-control" placeholder="yyyy-mm-dd" formControlName='date'
ngbDatepicker #d="ngbDatepicker">
</form>
In the component:
this.myForm = this.formBuilder.group({
date: [dateVariable, [Validators.required]]
});
Since I am using this in app.modules.ts
providers: [{ provide: NgbDateAdapter, useClass: NgbDateNativeAdapter }]
all datepickers neatly put out native Date objects. I just don't seem to be able to preset the value.
I tried this for testing:
<input class="form-control" placeholder="yyyy-mm-dd" [ngModel]='today'
ngbDatepicker #d="ngbDatepicker">
and it seems to work with [ngModel], but unfortunately my datepicker is part of a bigger form (this is a minimal example) and I would really appreciate it if I could just set the date.
I have read through quite a number of SO-pages now, many questions seem similar, but they often don't use reactive form or the NgbDateNativeAdapter provider.
Is it possible to set the date, using native dates. Maybe I must somehow tinker some references, my knowledge isn't that advanced yet.
If someone could give me a hint, I'd be so happy.