我一直在试图销毁PlatformRef。整个目的是优化应用程序内存(例如清除注入到根目录中的服务中的大量数据/订阅)。
正如社区所指出的那样,销毁平台并不是要走的路。从DOM中删除自定义元素后,如何销毁Angular服务?
在AppModule中,使用以下方式创建WebComponent
private void BtnClick_Click(object sender, System.EventArgs e)
{
MyDialog dialog = new MyDialog();
dialog.Show(SupportFragmentManager, "dialog");
}
该项目已构建并作为WebComponent加载到另一个项目中。
想象另一个项目包含许多选项卡,例如Chrome浏览器,每个选项卡将呈现一个WebComponent。
ngDoBootstrap(appRef: ApplicationRef) {
if (environment.name === 'createAsWebComponent') {
// ~~ For production ~~
if (!customElements.get('my-web-component')) {
customElements.define('my-web-component', createCustomElement(AppComponent, { injector: this.injector }));
}
} else {
// ~~ For dev ~~
appRef.bootstrap(AppComponent);
}
}
将由AppComponent调用PlatformRef.destroy()
的问题是,由于PlatformRef不再可用(由于在Tab A关闭期间被销毁),在关闭后再次重新打开Tab A将无法启动。