Reputation: 13636
I use angular 8. In my html I need to display current date.
Here is html code:
<label class="col-md-4">Creation date </label>
<input type="date" class="form-control" formControlName="date"/>
How can I display in html above current date?
Upvotes: 1
Views: 2663
Reputation: 22203
For reactive form, you can try like this:
myForm:FormGroup;
this.myForm = new FormGroup({
'date': new FormControl((new Date()).toISOString().substring(0,10))
});
Upvotes: 3
Reputation: 222702
In your component.ts file, you can get the date as,
export class AppComponent implements OnInit {
dateVal = new Date();
and display in the component.html, if you want to format you can use DatePipe
as you need
{{dateVal | date: 'M/dd/yyyy'}}
If you need to display in input, you can do
<input type="date" [ngModel] ="dt | date:'yyyy-MM-dd'" (ngModelChange)="dt = $event">
Upvotes: 3