简体   繁体   English

获取AngularJS指令以在iframe中工作

[英]Getting an AngularJS directive to work in an iframe

I am trying to get an angular directive to function inside of an iframe. 我试图获得一个角度指令在iframe内部运行。 The iframe is not from an external domain and is need so styles of the app that contains the iframe aren't applied to the content in the iframe. iframe不是来自外部域,因此需要将包含iframe的应用样式应用于iframe中的内容。

Here is a simple Plunker of what I am needing to do. 这是我需要做的简单的Plunker

As you can see the element with the my-draggable directive functions outside of the iframe but not within. 正如你可以看到带有my-draggable指令的元素在iframe之外但不在iframe之内。

As far as I can tell these are recognized as having the same origin, hence the ability of the parent page to inject content into the iframe. 据我所知,这些被认为具有相同的来源,因此父页面将内容注入iframe的能力。 I have also tried setting document.domain for both the iframe and the parent page. 我也尝试过为iframe和父页面设置document.domain。 Same results. 结果相同。

Is this a same origin policy issue or is it related to Angular scope? 这是一个相同的原产地政策问题还是与Angular范围相关?

Angular won't descend into the iframe during its compile phase, since the iframe is a separate DOM. Angular在编译阶段不会下降到iframe,因为iframe是一个单独的DOM。 In theory you could pass ifrm.innerWindow.document.body to $compile , then link it to a fresh scope. 理论上你可以将ifrm.innerWindow.document.body传递给$compile ,然后将它链接到一个新的范围。 But at that point your iframe has become a very clunky ngInclude , so why not just use that? 但是ngInclude你的iframe变得非常笨拙,所以为什么不用它呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM