我正在嘗試在我的應用程序中使用 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 中看到一個具有最少代碼的項目來重現它任何線索或幫助都非常受歡迎!
Zone.js 檢測到 ZoneAwarePromise
慕絲7291255
2021-10-21 14:49:15