在iframe中使用angularjs变量 [英] Using angularjs variable inside iframe

查看:85
本文介绍了在iframe中使用angularjs变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想在iframe src或ng-src属性中使用变量. 显然,无论我使用什么变量,我的变量都不会被识别. 例如`

So I want to use a variable inside a iframe src or ng-src attribute. Apparently none of my variables get ever recognized, whatever I use. For example `

<iframe ng-src="http://www.example.com/?name={{test}}">
</iframe>

其中的测试只是显示为{{test}} ....

where test just get displayed as {{test}} ....

此外,当我使用$sce将其用作受信任的url时,它不起作用,对于普通src来说也是如此.

Also when I use $sce to use it as a trusted url it doesn't work, same goes for normal src..

有什么我看不到的东西吗?关于iframe和angularjs吗? 请分享,这真的很烦人.

Is there something I don't see? Is there something about Iframes and angularjs? Please share, its really annoying.

提前Thnx.

推荐答案

您可以尝试一下, 在您的控制器中- 替换ng-src="{{test}}"-在整个网址中使用一个变量. 然后-

You can try this, In your controller do - replace the ng-src="{{test}}" -- use a variable for the whole url. and then -

$scope.test=$sce.trustAsResourceUrl("https://www.example.com");

在控制器依赖项中还包含$ sce.

also include $sce in your controller dependency.

对我有用. 希望对您有所帮助.

It worked for me.. Hope it helps.

这篇关于在iframe中使用angularjs变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆