I'm trying to use a datepicker and it doesn't seem to be displaying in the input control. The data is coming back correctly because I can pipe it out to the screen and see it.
Angular version: "@angular/core": "~11.2.11"
bootstrap version: "@ng-bootstrap/ng-bootstrap": "^10.0.0", "bootstrap": "^4.6.0"
Data (date) being returned:
"2020-10-21T09:39:04.357"
I would like to output just month, day and year.
even if I return a string of "2016-05-10" that does not display either.
If I select a date from the calendar it updates my model correctly. It displays it as:
{ "year": 2021, "month": 8, "day": 12 }
I tried declaring a variable and binding to that and it didn't work either. My variable was :
bsValue = new Date();
<div class="input-group">
<input class="form-control" placeholder="yyyy-mm-dd"
name="lastActivityDate" [(ngModel)]="user.lastActivityDate"
ngbDatepicker #d2="ngbDatepicker">
<div class="input-group-append">
<div class="input-group-text" (click)="d2.toggle()">
<i class="fa fa-calendar" style="cursor: pointer;"></i>
</div>
</div>
</div>
In your component add the DatePipe to the constructor and initialize your date:
In your template:
type="date" will make it so the format of the date is localized. If your browser is set to a locale where the format is 'dd-MM-yyyy' it will be shown the way you want.
In yout module: