我正在尝试在我的应用程序中使用 Typeform 库,但是我遇到了很多问题。加载 js 脚本后,Angular 区域错误,我收到此消息:错误:Zone.js 检测到 ZoneAwarePromise(window|global).Promise已被覆盖。最可能的原因是在 Zone.js 之后加载了 Promise polyfill(加载 zone.js 时不需要 Polyfilling Promise api。如果必须加载,请在加载 zone.js 之前加载。)我的 app.component.ts 的代码是:import { Component, Inject, AfterViewInit} from '@angular/core';import { DOCUMENT } from '@angular/common';import * as typeformEmbed from '@typeform/embed';@Component({ selector: 'my-app', template: `<div #my_typeform></div>`,})export class AppComponent implements AfterViewInit { constructor( @Inject(DOCUMENT) private document: Document ){} ngAfterViewInit() { const element = this.document.getElementById.call(document, 'my_typeform'); typeformEmbed.makeWidget(element, 'https://jonathan.typeform.com/to/zvlr4L', { onSubmit: () => console.log('Close') }); }}我尝试手动运行 ngZone 以确保它在 Angular zone 内运行,但没有奏效。在这种情况下, app.component.ts 就像import { Component, Inject, AfterViewInit, NgZone} from '@angular/core';import { DOCUMENT } from '@angular/common';import * as typeformEmbed from '@typeform/embed';@Component({ selector: 'my-app', template: `<div #my_typeform></div>`,})export class AppComponent implements AfterViewInit { constructor( @Inject(DOCUMENT) private document: any, @Inject(NgZone) private ngZone: NgZone ){} ngAfterViewInit() { this.ngZone.run(() => { const element = this.document.getElementById.call(document, 'my_typeform'); typeformEmbed.makeWidget(element, 'https://jonathan.typeform.com/to/zvlr4L', { onSubmit: () => console.log('Close') }); }); }}我还尝试在我的 polyfill.ts 文件中导入 'zone.js/dist/zone-patch-rxjs',但它也不起作用。您可以在https://stackblitz.com/edit/angular-issue-repro2-daytbo 中看到一个具有最少代码的项目来重现它任何线索或帮助都非常受欢迎!
添加回答
举报
0/150
提交
取消