在Angular 7中,Zone.js和自定义元素可能会引起一些问题。下面是一些解决方法,包含代码示例:
import { NgZone } from '@angular/core';
export class CustomElement extends HTMLElement {
constructor(private ngZone: NgZone) {
super();
this.ngZone.run(() => {
// 在Zone.js的回调函数中执行自定义元素的构造函数逻辑
});
}
}
import { NgZone, ApplicationRef } from '@angular/core';
export class CustomElement extends HTMLElement {
private appRef: ApplicationRef;
constructor(private ngZone: NgZone) {
super();
this.ngZone.run(() => {
this.appRef = ngZone.injector.get(ApplicationRef);
});
}
connectedCallback() {
this.ngZone.run(() => {
this.appRef.tick();
});
}
}
以上是解决Angular 7中Zone.js和自定义元素问题的一些方法,希望对你有帮助。