I use the below to generate date in component.ts file:
this.myDate=new Date();
And try to use in html form value field.But nothing is loaded.I have tried both the below syntax but not succesful
<input type="datetime" class="form-control" id="date" value={{this.myDate}} name="created" ngModel>
<input type="datetime" class="form-control" id="date" [value]=[this.myDate] name="created" ngModel>
One more issue is that my json file is upadted with only empty string after add operation
You are missing the right date format for the input type datetime that is ="2017-06-01T08:30"
in the component.ts
formatted_date:string;
ngOnInit(){
//your code...
this.formatted_date = this.myDate.toISOString();
this.formatted_date.slice(0,16);
}
In the template.html (change the type to datetime-local beacuse datetime is Obsolete MDN Doc)
<input type="datetime-local" class="form-control" id="date" value="{{formatted_date}}" name="created">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With