首页 > 解决方案 > EventEmitter 类型上不存在观察到的属性

问题描述

我们使用 angular (11.2.14) 并将 rxjs 库更新到 7.1.0。从那时起,我们在多个地方都有这个错误“属性'观察者'不存在于类型'EventEmitter'上”。根据我们发现的 PR(https://github.com/ReactiveX/rxjs/pull/6405#issue-645234112),应该观察到一个属性,但它不可用,因为我们使用的是 EventEmitter 而不是 Subject。

错误出现在构建上。

@Output() readonly onListCreate: EventEmitter<ListDto> = new EventEmitter(); // our emitter

createList() {
        if (!this.newListName) {
            return;
        }

        this.ListService.createList(this.newListName).subscribe((newList) => {
            const newListViewModel: ListViewModel = {
                id: newList.id,
                name: this.newListName,
                isAdded: false,
            };
            this.addModuleToList(newList, newListViewModel);
            this.newListName = "";

            if (this.onListCreate.observers.length === 0) { // error appears here
                this.listsViewModel.push(newListViewModel);
                this.ownedAndCoOwnedLists.push(newList);
            }

            this.onListCreate.emit(newList);
        });
}

标签: node.jsangulartypescriptrxjsangular-event-emitter

解决方案


推荐阅读