我正在尝试在我的 Angular 模板中加载外部页面。但是,出于身份验证目的,我需要将 sess_id 值与 url 一起传递。我在我的 div 中添加了一个 iframe,并调用了 url 和 sess_id 值。在我的模式中正确检索了 sess_id 值。但我无法在 Iframe 中加载页面。
我要检索的 url 结构应该类似于“urlhere?ss_id=bfc443c761de8b2ba18c82fecc50fd77”
<section class="panel panel-default" data-ng-controller="loginController">
<div class="panel-body" style=" position: relative;">
<div id="report_loader" style="min-height:600px;">
{{sess_id}} // i can retrive the value here
<iframe ng-src="{{ 'urlhere?ss_id=' + sess_id }}"> </iframe>
</div>
</div>
</section>
我们将不胜感激任何帮助。
最佳答案
使用指令
angular.module('testModule').directive('iframeDr', function ($compile) {
return {
restrict: 'AE',
//terminal:true,
link: function(scope, element, attr) {
var tryme = scope.sess_id
var ele = $compile('<iframe ng-src="urlhere?ss_id={{'+tryme+'}}"> </iframe>')(scope);
element.replaceWith(ele);
}
}
})
并将指令添加到您的 iframe
<iframe ng-src="{{ 'urlhere?ss_id=' + sess_id }}" iframe-dr></iframe>
关于javascript - 在 Angular JS 中检索 Iframe 内的数据绑定(bind)值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27393328/