When attempting to apply multiple filters in a quick session, I am encountering an issue where the previous data persists in the array alongside the new data. How can I effectively remove the previous data?
component.ts
ngOnInit() {
this.vehicleAttribute = JSON.parse(sessionStorage.getItem('vehicleAttributes'));
const data: ProductCatalogPostData = {
vehicleModelAttributes: this.vehicleAttribute.vehicleModels[0].modelAttributes,
role: 'vehicle owner',
planType: this.planType
};
const page: ProductCatalogPostPagination = {
page: this.pageNo
};
this.productCatalogService.compatibleProducts(data, page.page).subscribe(
response => {
for (let i = 0; i < response.products.length; i++) {
this.lists.push(response.products[i]);
}
this.pageCount = response.totalCount;
},
error => {
console.log(error);
}
);
}
In my filter function, I attempt to empty the list.
onSelectedChange($event) {
this.lists = [];
this.planType = $event[0]
this.ngOnInit();
}
However, I am still seeing the previous subscribed data in addition to the new data. Any suggestions would be greatly appreciated.