[英]Using angularjs variable inside iframe
So I want to use a variable inside a iframe src or ng-src attribute.所以我想在 iframe src 或 ng-src 属性中使用一个变量。 Apparently none of my variables get ever recognized, whatever I use.
显然,无论我使用什么,我的变量都没有被识别出来。 For example `
例如`
<iframe ng-src="http://www.example.com/?name={{test}}">
</iframe>
where test just get displayed as {{test}}
....其中 test 只是显示为
{{test}}
....
Also when I use $sce
to use it as a trusted url it doesn't work, same goes for normal src..此外,当我使用
$sce
将其用作受信任的 url 时,它不起作用,普通 src 也是如此..
Is there something I don't see?有什么我看不到的吗? Is there something about Iframes and angularjs?
有关于 Iframes 和 angularjs 的东西吗? Please share, its really annoying.
请分享,它真的很烦人。
Thnx in advance.提前谢谢。
You can try this, In your controller do - replace the ng-src="{{test}}"
-- use a variable for the whole url.你可以试试这个,在你的控制器中 - 替换
ng-src="{{test}}"
- 对整个 url 使用一个变量。 and then -进而 -
$scope.test=$sce.trustAsResourceUrl("https://www.example.com");
also include $sce in your controller dependency.还将 $sce 包含在您的控制器依赖项中。
It worked for me.. Hope it helps.它对我有用..希望它有帮助。
You can set the src property with this syntax:您可以使用以下语法设置 src 属性:
iframeObject.src = URL
iframeObject.src = URL
To note : URL specifies the URL of the content to embed and it can be either an absolute or a relative URL.注意: URL指定要嵌入的内容的 URL,它可以是绝对 URL 或相对 URL。
Example:例子:
document.getElementById('embedContent').src = "http://www.example.com";
#embedContent{ width: 600px; height: 500px; }
<iframe id="embedContent" src="#"></iframe>
Because you also want to concatenate / merge two strings, you can just change the JavaScript to因为您还想连接/合并两个字符串,您只需将 JavaScript 更改为
document.getElementById('embedContent').src = "http://www.example.com/?name=" + test;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.