首页 > 解决方案 > 如何将外部变量传递给 Angular Iframe?

问题描述

我创建了一个简单的 Angular 应用程序并将其投入生产。在另一个项目中,我通过 iframe 调用了它。

iframe 显示正确,但我不知道如何将变量传递给 iframe 内的应用程序。

我试过这个:

Parent App
<iframe src="https://{myBusinessUri}.amazonaws.com/index.html?id=12345"></iframe>

Iframe App > App.Module
ngOnInit(): void {
    this.getQueryParam();
  }

  getQueryParam() {
    this.activatedRoute.queryParams.subscribe(params => {
      const id = params['id'];
      console.log(id);
    });
  }

如果我将 id 添加到 iframe,则会发生错误。

Error: Cannot match any routes. URL Segment: 'index.html'

我还尝试将查询参数 id 放在父应用程序的路径中,但没有成功。

标签: angulariframe

解决方案


推荐阅读