我正在尝试在我的应用程序中使用 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 区域内运行,但没有成功。在这种情况下,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 https://stackblitz.com/edit/angular-issue-repro2-daytbo
非常欢迎任何线索或帮助!
提前致谢!