I am encountering an issue with storing and retrieving objects of type Order
in localstorage. Even though the information stored remains the same, when refreshing the page, the object loses its type identification as Order
. This prevents me from being able to call the function getFullName()
. The actual Order
class is quite expansive and I would prefer not to create a new instance using new Order()
every time I retrieve the object from localstorage. I have attempted writing an adapt(order: any): Order
function to address this, but it becomes complicated when dealing with data from the database that may have different property names (e.g., Name
instead of sName
). Writing another function like adapt2(order): Order
for such cases would be cumbersome. Can you suggest a better approach for resolving this issue?
ngOnInit(){
this.order = this.localstorage.retrieve('order') // order.getFullName() is not known
// should I write a new adapt function or would you recommend me to do something else?
}