title: AngularJS postmessage to iframe
body: <p>I am looking for a way to obtain an iframe contentWindow object and post a message to it after some action of the user. My current solution does not feel ok with angular at all (especially accessing the DOM from the controller).</p>
  
  <p>I have created a plunker demonstrating the issue:
  <a href="http://plnkr.co/edit/aXh4jydWGWfK3QQD4edd" rel="noreferrer">http://plnkr.co/edit/aXh4jydWGWfK3QQD4edd</a></p>
  
  <p>Is the a more angular way to execute the postMessage?</p>
  
  <p>controller:</p>
  
  <pre><code>app.controller('Main', function($scope) {
    $scope.click = function() {
      var iframe = document.getElementById("inner").contentWindow;
  
      iframe.postMessage("Hello iframe", '*');
    }
  });
  </code></pre>
  
  <p>html:</p>
  
  <pre><code>  &lt;body ng-controller="Main"&gt;
      &lt;button ng-click="click()"&gt;send message&lt;/button&gt;
  
      &lt;iframe id="inner" src="inner.html"/&gt;
    &lt;/body&gt;
  </code></pre>