title: $postLink of an angular component/directive running too early
body: <p><strong>Update:</strong> I put a bounty on this question. I am not looking for hacks or workarounds. I am looking for an official way to access the dom in an angular component, and an explanation why the behavior I see ($postLink running to early) seems to be contradictory to the official docs.<br>
  The official docs state (<a href="https://docs.angularjs.org/guide/component">here</a>):</p>
  
  <blockquote>
    <p>$postLink() - Called after this controller's element and its children have been linked. Similar to the post-link function this hook can be used to set up DOM event handlers and do direct DOM manipulation</p>
  </blockquote>
  
  <p><strong>Original question:</strong> I have an example of the problem here -> <a href="http://plnkr.co/edit/rMm9FOwImFRziNG4o0sg?p=preview">http://plnkr.co/edit/rMm9FOwImFRziNG4o0sg?p=preview</a></p>
  
  <p>I am using an angular component and I want to modify the dom in the post link function, but it doesn't work, it seems that the function runs too early, before the template is actually ready in the dom after all the angular processing.</p>
  
  <p>In the html page, I have this:</p>
  
  <pre><code>&lt;my-grid grid-id="'foo'"&gt;&lt;/my-grid&gt;
  </code></pre>
  
  <p>The component is defined as:</p>
  
  <pre><code>appModule.component('myGrid',{
      controller: gridController,
      bindings: {
          "gridId": "&lt;",
      },
      templateUrl: 'gridTemplate'
  });
  </code></pre>
  
  <p>In the component template I have this:</p>
  
  <pre><code>&lt;table id='{{$ctrl.gridId}}'&gt;
  ...
  </code></pre>
  
  <p>(The binding itself works, there is no doubt. Eventually, in the html the id of the table is 'foo' as expected).</p>
  
  <p>In the controller, I have something like this:</p>
  
  <pre><code>function gridController($scope, $compile, $attrs) {
      console.log ("grid id is: " + this.gridId); // 'foo'
  
      this.$postLink = function() {
          var elem = document.getElementById(this.gridId);
          // do something with elem, but elem is null
      }
  }
  </code></pre>
  
  <p>What I see when debugging is that when the $postLink function is executed, the table is in the dom but its id attribute is still <code>{{$ctrl.gridId}}</code> instead of <code>foo</code>, so <code>document.getElementById()</code> finds nothing. This seems in contrast to the documentation.<br>
  What am I missing? Is there a different way to access the dom in the component?</p>
  
  <p><strong>Update 2:</strong> Today I realized the same problem occurs with the regular link function of directives, it is not limited to components. So apparently I misunderstood the meaning of "do direct DOM manipulation" - the link function runs on an element that is detached from the dom, so using the <code>document</code> object with selectors is useless.</p>