我使用角度自定义元素功能(element.js)创建了一个小应用程序,将那个element.js文件导入到index.html中的另一个angular(parent)应用程序中,在开发服务器(ng serve)元素功能正常,但是在生产模式下(ng build --prod)在element.js文件中得到此错误。
@ angular / core“:”〜8.1.3“,@ angular / elements”:“ ^ 8.1.3”
element (angular custom element code) polyfills.ts import 'zone.js/dist/zone'; // Included with Angular CLI. import "@webcomponents/custom-elements/src/native-shim"; import "@webcomponents/custom-elements/custom-elements.min"; app.module.ts export class AppModule { constructor(private injector: Injector) { } ngDoBootstrap() { const el = createCustomElement(NotificationElementComponent, { injector: this.injector }); // using built in the browser to create your own custome element name customElements.define('test-card', el); } }
angular (parent app) index.html
polyfills.ts import 'core-js/es6/reflect'; import 'core-js/es7/reflect'; import 'zone.js/dist/zone'; // Included with Angular CLI. (window as any).global = window;
app.component.html
错误Zone.js检测到ZoneAwarePromise (window|global).Promise
已被覆盖。最可能的原因是在Zone.js之后加载了Promise polyfill(加载zone.js时不需要填充Promise api。如果必须加载,则在加载zone.js之前执行。)。