title: Angular2 - Expression has changed after it was checked - Binding to div width with resize events
body: <p>I have done some reading and investigation on this error, but not sure what the correct answer is for my situation. I understand that in dev mode, change detection runs twice, but I am reluctant to use <code>enableProdMode()</code> to mask the issue.</p>
  
  <p>Here is a simple example where the number of cells in the table should increase as the width of the div expands. (Note that the width of the div is not a function of just the screen width, so @Media cannot easily be applied)</p>
  
  <p>My HTML looks as follows (widget.template.html):</p>
  
  <pre><code>&lt;div #widgetParentDiv class="Content"&gt;
  &lt;p&gt;Sample widget&lt;/p&gt;
  &lt;table&gt;&lt;tr&gt;
     &lt;td&gt;Value1&lt;/td&gt;
     &lt;td *ngIf="widgetParentDiv.clientWidth&gt;350"&gt;Value2&lt;/td&gt;
     &lt;td *ngIf="widgetParentDiv.clientWidth&gt;700"&gt;Value3&lt;/td&gt;
  &lt;/tr&gt;&lt;/table&gt;
  </code></pre>
  
  <p>This on its own does nothing. I'm guessing this is because nothing is causing change detection to occur. However, when I change the first line to the following, and create an empty function to receive the call, it starts working, but occasionally I get the 'Expression has changed after it was checked error'</p>
  
  <pre><code>&lt;div #widgetParentDiv class="Content"&gt;
     gets replaced with
        &lt;div #widgetParentDiv (window:resize)=parentResize(10) class="Content"&gt;
  </code></pre>
  
  <p>My best guess is that with this modification, change detection is triggered and everything starts responding, however, when the width changes rapidly the exception is thrown because the previous iteration of change detection took longer to complete than changing the width of the div.</p>
  
  <ol>
  <li>Is there a better approach to triggering the change detection?</li>
  <li>Should I be capturing the resize event through a function to ensure
  change detection occurs?</li>
  <li>Is using #widthParentDiv to access the
  width of the div acceptable? </li>
  <li>Is there a better overall solution?</li>
  </ol>
  
  <p>For more details on my project please see <a href="https://stackoverflow.com/questions/38518016/angular2-respond-to-div-size">this</a> similar question.</p>
  
  <p>Thanks</p>