【问题标题】:ObjectUnsubscribedError: object unsubscribedObjectUnsubscribedError:对象取消订阅
【发布时间】:2018-03-21 12:36:44
【问题描述】:

ObjectUnsubscribedError: object unsubscribed,有时(不是每次)在文本框中输入任何值时


HTML

<input #gb type="text" pInputText class="ui-widget ui-text"
[(ngModel)]="gb.value" (ngModelChange)="clearFilter(gb.value)" placeholder="Find" />

component.ts

clearFilter(newValue) {
        this.infomessage = [];
        this.errormessage = [];
        this.isDelete = false;
        this.isDefaultLoad = false;
        if (this.oldFilterText === '' && newValue === '') {
            return false;
        }
        this.oldFilterText = newValue;
        if (this._configuration.isNullOrEmptyOrUndefined(newValue)) {
            this.sortField = '';
            if (!this._configuration.isNullOrEmptyOrUndefined(this.dataTable.sortField)) {
                this.sortField = this.dataTable.sortField;
            }
            this.dataTable.reset();
            this.tempFilteredRecords = [];
            this.getApprovalTypelist();
            this.dataTable.sortField = this.sortField;
            this.dataTable.sortMode = 'single';
            this.dataTable.sortOrder = this.sortOrder;
        }
    }

我的代码运行良好!但有时在文本框中输入时会出错。此外,clearFilter 在收到此错误后也不会触发。

错误ObjectUnsubscribedError:对象取消订阅

我已经尝试过这个(但我不知道下面的这些链接是否与我的缺陷相关)下面的讨论

Angular 2 object unsubscribed error

ObjectUnsubscribedError when trying to prevent subscribing twice

Exception: ObjectUnsubscribedError when working with Observables with RxJS and Angular2

ObjectUnsubscribedError when trying to prevent subscribing twice

但一切都对我没有帮助。请带我摆脱这个不可预知的缺陷:(

【问题讨论】:

    标签: javascript html angular typescript observable


    【解决方案1】:

    我终于得到了答案,我刚刚使用下面的代码取消订阅onFilter() 事件

    this.dataTable.onFilter.unsubscribe();
    

    感谢您的意见!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-02
      • 1970-01-01
      • 1970-01-01
      • 2016-10-31
      • 1970-01-01
      • 2022-01-19
      • 2017-12-18
      • 2012-03-14
      相关资源
      最近更新 更多