angular - Angular datatable unsubscription error while closing ngx-bootstrap modal
问题描述
I am using Angular DataTable with ngx-bootstrap modal. When I close the modal the datatable throws unsubscription error and datatable does not initialize. I tried multiple workaround with re-render, unsubscribe on onHide event and it did not solve. Please help if anyone knows how to fix it
this.subscriptions.push(
this.modalService.onHidden.subscribe((reason: string) => {
alert('Hidden');
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
alert('Destroying..')
//Clear the table first
dtInstance.clear();
// Destroy the table
dtInstance.destroy();
})
this.dtTriggerFreshness.unsubscribe();
})
);
解决方案
存在上下文错误。
let trigger=this.dtTriggerFreshness;
let dtElementVar= this.dtElement;
let modalServiceVar=this.modalService;
this.subscriptions.push(
modalService.onHidden.subscribe((reason: string) => {
alert('Hidden');
dtElementVar.dtInstance.then((dtInstance: DataTables.Api) => {
alert('Destroying..')
//Clear the table first
dtInstance.clear();
// Destroy the table
dtInstance.destroy();
trigger.dtTriggerFreshness.unsubscribe();
})
})
);
现在它必须工作。
推荐阅读
- python - Python烧瓶数据库检索
- android - react-native-webview 不支持 Android 中的数学标签
- javascript - webpack babel loader with eslint laoder
- mysql - 无法在mysql中声明变量
- angular - Angular 9 ng-if 和 ng-show - 始终显示元素
- javascript - 单击按钮执行功能时页面会闪烁,但预期的结果永远不会发生
- javascript - 导航栏不以反应状态隐藏
- python - Dask 可视化方法图像尺寸太小
- android - 有没有办法组合来自不同维度的数据?
- c# - ICommand HasErrors 不会冒泡到父级