【问题标题】:AngularJS directive for updating IFrame's body用于更新 IFrame 正文的 AngularJS 指令
【发布时间】:2014-06-05 10:50:22
【问题描述】:

我想将模型属性绑定到 iframe 的主体。

使用 jQuery,逻辑必须写成类似

$('iframe').contents().find('body').html('<p>Hello</p>');

理想情况下,我希望 AngularJS 指令类似于..

<myframe body="model.safehtml"></myframe>

谁能指出我正确的方向?

谢谢

【问题讨论】:

    标签: javascript angularjs iframe angularjs-directive


    【解决方案1】:

    您可以在 Angular directivelink 函数中更改 DOM。

    app.directive('myframe', function($compile) {
      return {
        restrict: 'E',
        scope: {
            body: '='
        },
        template: "<iframe></iframe>",
        link: function(scope, elm, attrs) {
            elm.find('iframe').contents().find('body').html(scope.body);
        }
      };
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-02
      • 2015-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多