0

我有一个角度组件,其中包含我的 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 容器。

感谢您的任何支持。

4

0 回答 0