【问题标题】:ERROR ObjectUnsubscribedErrorImpl in using angular-datatable using angular 7ERROR ObjectUnsubscribedErrorImpl in using angular-datatable using angular 7
【发布时间】:2019-07-15 07:26:48
【问题描述】:

我正在尝试在模型窗口中显示数据表。 我第一次可以按预期查看屏幕。关闭模型窗口后,现在我试图在模型窗口中查看结果,但是从第二次开始,Datatable 没有显示搜索框,分页。

谁能帮我解决这个问题。

预期:

秒:

错误:

my.component.ts

    @ViewChild(DataTableDirective)
    dtElement: DataTableDirective;

    dtOptions: DataTables.Settings = {};

    // We use this trigger because fetching the list of persons can be quite long,
    // thus we ensure the data is fetched before rendering
    dtTrigger: Subject<any> = new Subject();

    ngOnInit() {
    this.service.getQueryResult(this.saveIteratorParams).subscribe( data => {
          if (data.success !== false) {
            this.queryViewResultL = data.payload;

            this.tableDataList = data.payload.molResults;

            if (this.tableDataList !== null || this.tableDataList !== undefined) {
              this.theadData = Object.keys(this.tableDataList[0]);

              // Calling the DT trigger to manually render the table
              this.dtOptions = {
                pagingType: 'full_numbers',
                pageLength: 10
              };

              this.dtTrigger.next();
            }
    }

    ngAfterViewInit(): void {
        this.dtTrigger.next();
        // console.log('ngAfterViewInit');
      }

      rerender(): void {
        this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
          // Destroy the table first
          dtInstance.destroy();
          // Call the dtTrigger to rerender again
          this.dtTrigger.next();
          // if (this.dtTrigger.observers) { this.dtTrigger.next(); }
        });
      }

      ngOnDestroy(): void {
        // Do not forget to unsubscribe the event
        this.dtTrigger.unsubscribe();
        console.log('this.dtTrigger.unsubscribe()', this.dtTrigger);

      }

【问题讨论】:

    标签: angular typescript datatable


    【解决方案1】:

    我不知道你的具体问题。我在处理我的项目时收到了同样的错误。此错误通常表示订阅者或主要方法被其他代码修改,导致其取消订阅。您可以使用开发人员工具对其进行调试。在右侧,您会找到手表。在此处写入表达式名称,例如 this.service.getQueryResult(this.saveIteratorParams)。从这段代码中,我认为破坏正在中断它。

    【讨论】:

    • 谢谢,我按你说的试过了,即使取消订阅,还是不行。你能喜欢一些调试工具吗?
    • 我个人只用了chrome的调试工具/开发工具。是否还有其他地方正在修改对象?如果您可以提供 jsfiddle 或其他东西来重新创建此问题,我可能会提供帮助。
    猜你喜欢
    • 2018-05-17
    • 2020-05-17
    • 1970-01-01
    • 2021-01-08
    • 1970-01-01
    • 2022-12-28
    • 2022-10-05
    • 1970-01-01
    • 2013-09-20
    相关资源
    最近更新 更多