我想清除 ngOnDestroy 上的数据。我从服务中获取这些静态数据。当前的情况是我使用相同的组件进行添加编辑,我只想在用户完成编辑后清除临时静态数据。
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;
}
}
在组件中:
constructor(
private defaultData: LeadsDefaultDataService,
) {
}
// For getting the data
this.leadsData = this.defaultData.getLeadsDefaultData('leads');
// Reset the leadsData.
ngOnDestroy() {
this.leadsData = null; // not working....
}