ObjectUnsubscribedError:对象unsubscribed

时间:2017-10-10 07:36:08

标签: javascript html angular typescript observable

ObjectUnsubscribed错误:对象取消订阅,有时(不是每次)在文本框中输入任何值

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

  

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

1 个答案:

答案 0 :(得分:2)

最后我得到了答案,我刚刚使用以下代码取消订阅onFilter()事件

this.dataTable.onFilter.unsubscribe();

感谢您的意见!