简体   繁体   中英

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, unsubsc 在此输入图像描述 ribe 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();
      })
    );

There are a context error.

    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();
               })

          })
        );

Now it must work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM