在 Angular JS 中检索 Iframe 中的数据绑定值

Retrieving the data binding value inside Iframe in Angular JS

本文关键字:数据绑定 Iframe 检索 Angular JS      更新时间:2023-09-26

我正在尝试在我的角度模板中加载外部页面。但是,我需要传递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>

任何帮助都将受到高度赞赏。

use 指令

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>