Abhishek joshi
Abhishek joshi

Reputation: 11

how to change html input type date placeholder value as a curruent Date i m using angular

<input type="date" name ="Date"
   class="form-control" [formControl]="dateCtrl">
getDateCtr() {

    var today = new Date(this.dateCtrl.value);
    var dd = String(today.getDate() ).padStart(2, '0');
    var mm = String(today.getMonth()+1).padStart(2, '0');
    var yyyy = today.getFullYear();
    this.date = dd + '-' + mm + '-' + yyyy;
    this.loadAll();

  }

Upvotes: 0

Views: 107

Answers (1)

Brian
Brian

Reputation: 328

I used the information from Mozilla regarding date, and all that you are missing in your HTML is the value option:

<input type="date" name ="Date" class="form-control" value="{{getDateCtr()}} [formControl]="dateCtrl">

I do not know what the this.loadAll() is meant to accomplish. But the JS I worked with looked like this:

getDateCtr() :string {
    var today = new Date();
    var d = today.getDate().toFixed().padStart(2, '0');
    var m = (today.getMonth() + 1).toFixed().padStart(2, '0');
    var y = today.getFullYear().toFixed();
    var sday = y + "-" + m + "-" + d
    return sday;
    }

Note that the return type is :string for the function.

Upvotes: 1

Related Questions