昨天,我将我的应用程序从Angular 5迁移到了angular7。在此过程中,我在运行应用程序时按照建议将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');
任何人都可以建议我如何摆脱这个问题。
谢谢。
答案 0 :(得分:1)
您必须传递其他参数,如
eventSource = new EventSourcePolyfill(url,
{ heartbeatTimeout: 5000, connectionTimeout: 5000, headers: { 'Authorization': 'Basic foo' }});