I have an input field for an edit form which is supposed to give me a date when I click edit. From my spring back end I am getting a date in a long format eg. 164888330000. If I change the input type to text, I will get the long value of date but I want to get the date in the format yyyy-mm-dd because this is how I store my dates. Unfortunately, angular pipes cant be used in input as I understand
<label class="form-control-label" *ngIf="truckForm.get('date').invalid && processValidation"
[ngClass]="'error'"
for="purchasedDate">date is required.</label>
<input formControlName="date"
id="purchasedDate"
class="form-control"
type="date"
name="purchasedDate"
[(ngModel)]="truck.purchasedDate"/><strong>Purchased Date</strong>
</div
I am using formGroup here in my component class. Is there a way to convert the date to my desired format before they are shown in the UI? In angular.js it was possible to use new Date(long) and convert it but I'm not sure how to achieve this in angular 4
@Input() truck: Truck;
truckForm = new FormGroup({
truckCode: new FormControl('', Validators.required),
date: new FormControl('', Validators.required),
descriptions: new FormControl('', Validators.required)
});
processForm() {
this.processValidation = true;
if (this.truckForm.invalid) {
return; //Validation failed, exit from method.
}
// if we are here then all good
this.preProcessConfigurations()
let truckCode = this.truckForm.get('truckCode').value.trim();
let date = this.truckForm.get('date').value.trim();
let description = this.truckForm.get('descriptions').value.trim();
//this.dateString = new Date(this.truck.purchasedDate);
let truck = new Truck(this.truck.truckId, truckCode, date , description);
this.truckService.updateTrucks(truck).subscribe(successCode => {
this.statusCode = successCode;
this.router.navigate(['/trucks']);
}, errorCode => this.statusCode = errorCode);
}
This is an update function so I would like to receive the date in a yyyy-mm-dd format , any help on how I can accomplish that?