簡體   English   中英

AngularJS指令用於更新IFrame的主體

[英]AngularJS directive for updating IFrame's body

我想將模型屬性綁定到iframe的主體。

使用jQuery,邏輯必須寫成類似的東西

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

理想情況下,我希望AngularJS指令類似於..

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

誰能指出我正確的方向?

謝謝

您可以在Angular 指令link函數中更改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);
    }
  };
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM