1

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?

2 Answers 2

3

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">

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

How can I put it inside input tag
3

For reactive form, you can try like this:

myForm:FormGroup;

this.myForm = new FormGroup({    
 'date': new FormControl((new Date()).toISOString().substring(0,10))
});

Working Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.