gpt4 book ai didi

angular - instance[output.propName].subscribe 不是由 polyfill 生成的函数

转载 作者:太空狗 更新时间:2023-10-29 16:54:38 25 4
gpt4 key购买 nike

我遇到了一个奇怪的问题。我研究了这个错误,它通常似乎与 @OutputEventEmitter 的使用有关,但这里并非如此。

如果我有特定的 polyfill,我的应用程序会出现以下错误:

TypeError: instance[output.propName].subscribe is not a function
at createDirectiveInstance (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:12319:71)
at createViewNodes (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:13776:38)
at callViewAction (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:14210:1)
at execComponentViewsAction (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:14119:1)
at createViewNodes (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:13804:1)
at createRootView (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:13665:1)
at callWithDebugContext (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:15090:26)
at Object.debugCreateRootView [as createRootView] (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:14373:1)
at ComponentFactory_.webpackJsonp.../../../core/esm5/core.js.ComponentFactory_.create (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/core.js:11260:26)
at initComponent (http://localhost:9876/_karma_webpack_/webpack:/Users/stuart/localhost/projects/tt-new/work-group/node_modules/@angular/core/esm5/testing.js:1137:1)

polyfill如下:

Object.prototype.clone = function(deep = false) {
return (deep)
? JSON.parse(JSON.stringify(this)) // Deep clone - copies object property values in full.
: Object.assign({}, this); // Shallow clone - copies property values (including object references rather than object).
};

谁能帮我理解为什么这会在 createDirectiveInstance 中导致错误?如果我注释掉这段代码,错误就会消失。不仅仅是有一个 polyfill 会导致问题 - 还有另一个,它添加了 Array.prototype.upsert,它不会导致问题。

最佳答案

我刚刚遇到这个问题,检查我编写的代码后发现这是由于错误导入 EventEmitter 类(由 visual studio 代码自动导入完成)引起的。

你只需要改变

import { EventEmitter } from 'events';

import { EventEmitter } from '@angular/core';

以及关于错误的解释。 Angular 将事件映射为可观察对象,因此它必须订阅子组件的事件并将它们发送到适当的组件。

在寻找原始包时,我在以下位置找到了它的源代码:https://github.com/Gozala/events/blob/master/events.js

它只是失败了,因为在您创建的 EventEmitter 中没有方法 .suscribe()

关于angular - instance[output.propName].subscribe 不是由 polyfill 生成的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48596826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com