【问题标题】:component inside iframe angular2iframe angular2 中的组件
【发布时间】:2016-07-18 09:22:47
【问题描述】:

有没有办法在 Angular 2 的 iframe 中包含组件?

此代码不起作用(它应该在 iframe 中呈现名为 component-b 的 angular 组件):

  var doc = document.getElementById('iframe').contentWindow.document;
    doc.open();
    doc.write('<component-b></component-b>');
    doc.close();

这段代码有效(它在 iframe 中呈现一个简单的按钮):

 var doc = document.getElementById('iframe').contentWindow.document;
    doc.open();
    doc.write('<button></button>');
    doc.close();

【问题讨论】:

  • Angular 不处理动态添加的 HTML(不实例化绑定或组件/指令),不在 iframe 外部也不在内部。您可以尝试ViewContainerRef.createComponent(),如stackoverflow.com/questions/36325212/…中所示
  • 好的,谢谢甘特

标签: iframe angular components


【解决方案1】:

如果您在 angular2 应用程序中有一个 iframe,这意味着它是一个完全不同的上下文。 (单独申请)

由于上述原因,组件/绑定无法在那里工作。

你唯一能做的就是在你的 iframe 中引导另一个角度应用程序,但我确定你不想要那个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 2017-03-17
    • 1970-01-01
    • 2016-11-22
    • 2018-07-11
    • 1970-01-01
    相关资源
    最近更新 更多