javascript - 在 Angular JS 中检索 Iframe 内的数据绑定(bind)值

标签 javascript jquery html angularjs iframe

我正在尝试在我的 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/

相关文章:

javascript - 如何通过在普通 JavaScript 中动态附加的类名获取所有选择器?

javascript - 在 contenteditable 中插入自定义标签

javascript - jQuery - 拖放 - 获取 DROP 左侧和顶部位置

javascript - 调试时 Ajax 调用不起作用 ="false"(ASP.NET MVC)

java - 无法在 NVD3 中显示所有 X 轴刻度值

javascript - Ng-src 不会在 AngularJS View 中更新

javascript - 数据字符串如何包裹在对象内部?工作到 html 显示

Javascript keyup 函数抛出错误的警报消息

javascript - navigator.geolocation不稳定/不可靠,如何从浏览器获得稳定的读数?

javascript - 在 jQuery 中这样做有什么问题吗?