从Angular 5迁移到Angular 7

3

昨天我将我的应用程序从Angular 5迁移到了Angular 7。在此过程中,当我运行应用程序时建议我将EventSource更改为EventSourcePolyfill。但是自那以后,我一直面临奇怪的问题。这就是我在控制台中得到的问题:

ERROR TypeError: Cannot read property 'heartbeatTimeout' of undefined
    at new EventSourcePolyfill (eventsource.js:155)
    at AppFooterComponent.push../src/app/layout/footer/footer.component.ts.AppFooterComponent.connect (footer.component.ts:133)
    at SafeSubscriber._next (footer.component.ts:52)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:196)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:134)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:77)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
    at AsyncAction.dispatch (timer.js:31)
    at AsyncAction.push../node_modules/rxjs/_esm5/internal/scheduler/AsyncAction.js.AsyncAction._execute (AsyncAction.js:63)
    at AsyncAction.push../node_modules/rxjs/_esm5/internal/scheduler/AsyncAction.js.AsyncAction.execute (AsyncAction.js:51)

这是我在代码中所做的:

import { EventSourcePolyfill } from 'ng-event-source';

let source = new EventSourcePolyfill('/api/v1/events/register');

有谁可以给我建议如何解决这个问题。

谢谢。


错误的起源在footer.component.ts文件中(第133行),请在那里检查。heartbeatTimeout可能不在您尝试读取的对象的属性中。 - inthevortex
当我将其注释掉时,它就能正常工作。我的意思是EventSourcePolyfill被注释后,它就能正常工作。这不是footer.component.ts的问题。EventSourcePoyfill在footer.component.ts中的代码出现了问题。请提供建议。 - youi
你使用过 ng update 命令进行迁移吗?它有能力重构一些破坏性的更改吗?你是否遵循了 update.angular.io 上的说明?其中有一些步骤涉及 RxJS 迁移。 - Walter Luszczyk
1个回答

1

您需要传递额外的参数,如下:

eventSource = new EventSourcePolyfill(url,
    { heartbeatTimeout: 5000, connectionTimeout: 5000, headers: { 'Authorization': 'Basic foo' }});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接