首页 > 解决方案 > 如何从 iframe 向 Angular 应用程序传递值

问题描述

我有带有路线的 Angular 9 应用程序。

它嵌入到 iframe 中的 ASP.NET 应用程序中(我无法控制此设置,Angular 的/dist文件夹位于 ASP.NET 应用程序的文件夹结构中)。

一切正常,但新的要求是默认加载显式路由。

这是当前的设置:

<iframe src="[path]/index.html" />

寻找类似下面的东西(它会爆炸Error: Cannot match any routes. URL Segment: 'index.html'

<iframe src="[path]/index.html?r=whatever" />

问题:如何将值从其父 iframe 传递给 angular?(index.html必须在 中src,这似乎是 Angular 方面的主要问题)

标签: angulariframe

解决方案


您可以将事件发送到 iframe 并在 Angular 应用程序中对这些事件做出反应。

MDN postMessage


推荐阅读