我有一个 angular 组件,其中包含将要进行嵌入的 html 容器。现在在路由更改时,此组件将被销毁,其包含报告的 html 容器也将被销毁。当用户返回到报表路径时,组件将再次初始化并从头开始重新嵌入报表,删除用户对报表所做的任何更改。
我想知道是否有办法使报告在组件销毁时幸免于难。我想到了一些方法,例如使嵌入过程发生在从显示报告的组件调用的服务中。问题是我不知道如何实际设置它以及服务究竟应该返回什么:html 容器或 pbi.embed() 方法的结果?
这是当前从我的报告查看器组件 onInit 调用的方法。它注入了 powerbiService 以获取报告嵌入信息。实际嵌入当前发生在组件级别:
this.powerbiService
.getReportEmbedInfoById()
.subscribe(async (data) => {
if (this.pbiContainerElement) {
const embedConfig = this.powerbiService.buildEmbedConfig(data);
powerbi.reset(this.pbiContainerElement);
this.myReport = powerbi.embed(this.pbiContainerElement, embedConfig);
// report.off removes all event handlers for a specific event
this.myReport.off('loaded');
// report.on will add an event handler
this.myReport.on('loaded', () => {
this.powerbiService.handleTokenExpiration(this.myReport);
loadedResolve();
// this.myReport.off("loaded");
});
});
我在这里提供更多详细信息,以防它可能有助于获得答案: 进行嵌入的功能是这个:
this.myReport = powerbi.embed(this.pbiContainerElement, embedConfig);
它接受一个 html 容器并返回对嵌入报告的引用。 现在的问题是我们如何让这个容器从服务传递到组件,以便当组件被销毁时,它可以再次嵌入同一个 html 容器。
感谢您的支持。