我想在快速会话中使用多个过滤器,我正在获取数组中的先前数据以及新数据。如何删除以前的数据。在订阅之前重置数组angular2
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);
}
);
}
的过滤功能我想提出尽量使列表为空
onSelectedChange($event) {
this.lists = [];
this.planType = $event[0]
this.ngOnInit();
}
,但我还是以前的订阅数据与新的数据一起。任何输入的高度赞赏
从过滤函数调用'ngOnInit'绝对不是好。你永远不应该这样称呼它。整个观点是Angular称之为。 –
为什么你会期望不同的数据? 'productCatalogService.compatibleProducts'很可能会返回相同的结果,无论您是否没有任何参数化。 –
@AluanHaddad on'selectedChange'函数我得到了我的'planType'值,所以我用新的planType值调用了http请求。所以这就是我打电话给'ngOnInit()'的原因(如果有其他方法,请指导),并且我的计划类型值变化会得到不同的数据。我没有任何帮助地使用了debounce函数 – Prasadau