I am new to Angular and I have several doubts about what is the best way to serialize a Date property of an object added to a POST request. Given the sample class
export class MyClass{
public dateProperty: Date;
}
I have the following code in the service:
public addMyClass(myClass: MyClass): Observable<MyClass> {
return this.http.post<MyClass>(this.apiBaseUrl, myClass);
}
I have to serialize Date in the following format 'yyyy-MM-dd hh:mm'
.
I considered different ways like defining a decorator (if possible), or overriding toJson()
method, but I don't know if these are the only options or there is a better solution...