1

があり、iframeその内容はコントローラー関数にバインドする必要があります。私は試した

<iframe ng-bind-html-unsafe="selectedMessage.content()"></iframe>

しかし、残念ながらそれはうまくいかないようです。にコンテンツを書き込む正しい方法は、 DOM 要素にiframeアクセスしてを呼び出すことです。iframeifrmElem.contentDocument.write(s)

どうすればこれを達成できますか?

4

2 に答える 2

2

これを実現するには、プロパティにウォッチャーを設定し、必要に応じてiframeを手動で更新します。

以下の例では、クロスブラウザーのiframeコンテンツ選択を使用しています。

jsFiddleを参照してください:http://jsfiddle.net/uyLNY/2/

$scope.$watch('data.content', function(oldValue, newValue) {
    var ifrm = $element.find('iframe')[0];
    ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;       
    ifrm.document.open();
    ifrm.document.write(newValue);
    ifrm.document.close();

});

ただし、大量のコンテンツを作成する場合、これのパフォーマンスはわかりません。

于 2013-03-05T01:40:15.150 に答える
1

ここに plnkr があります: http://plnkr.co/edit/LG7p1AG7yhVKyLXgMX4Q?p=preview

Javascript

  $scope.content= "";

  $scope.fillFrame = function(id) {
    document.getElementById(id).contentDocument.write($scope.content);  
  };

HTML

 <strong>Enter some html</strong>
    <br/>
    <textarea ng-model="content"></textarea>
    <button ng-click="fillFrame('frame')">Fill iFrame</button>
于 2013-03-05T01:44:07.857 に答える