I need to clear the static data upon component destruction. The data is fetched from a service and currently, I am using the same component for both adding and editing purposes. My goal is to clear the temporary static data once the user has finished editing.
export class LeadsDefaultDataService {
tempData;
private leadsDefaults = {
leads: {
data: [
{
type: 'page_title',
data: {
title: 'Enter data',
}
},
{
type: 'page_layout',
data: {
backgroundColor: '#FFFFFF'
}
}
}
};
/**
* Constructor
*/
constructor(
) {}
/**
* Function used to return the default data of qrCategory
* @param category: Name of the category
*/
getLeadsDefaultData(category: string) {
return this.leadsDefaults[category].data;
}
}
In the component:
constructor(
private defaultData: LeadsDefaultDataService,
) {
}
// For getting the data
this.leadsData = this.defaultData.getLeadsDefaultData('leads');
// Reset the leadsData.
ngOnDestroy() {
this.leadsData = null; // not working....
}