I am using Angular 6 with reactive forms and I am trying to figure out how to format the date value returned from a webapi. The date is displaying as 1973-10-10T00:00:00 and I want to format it to 10/10/1973. Below is the code to retrieve the data and display it. The webapi json dob value is 1973-10-10T00:00:00. The dob value in the model is of type Date.
html
<input formControlName="dob" type="text" [value]="dob | date: 'MM/dd/yyyy'" class="form-control" />
binding form
this.userInfoForm = this.fb.group({
'userId': ['', [Validators.required]],
'dob': ['', [Validators.required]]
});
loading saving
this.as.accountUserInfo(this.activeRoute$.ActiveUserId).subscribe(data => {
this.userInfoModel$ = data as UserInfoModel;
this.userInfoForm.patchValue(this.userInfoModel$);
});
api call
accountUserInfo(userId: number) {
return this.http.post(this.url + "UserInfo", userId)
.pipe(
retry(3),
catchError(this.handleError)
)}
I appreciate any help or guidance as how to transform the date to the MM/dd/yyyy format. Setting the html to date value does make it look ok but I don't want to use the built in browser date displays so I need to convert it to a string.
Thanks in advance.