title: Using $location and $anchorScroll to scroll a table row into view
body: <p>I'm trying to use $anchorScroll to scroll down the page to ensure that a row of a table is shown.  I've read most of the SO threads and docs about $anchorScroll.  I'm using it correctly, as far as I can tell.  I've stepped through the code with Firebug, and it appears that the element id I'm using is correct.</p>
  
  <p>When I execute the function that should change the scroll location, it does change the scroll location, but it just scrolls up, going all the way to the top.  My "target" element that I want to scroll to is further down the page from where I execute the function.</p>
  
  <p>There are no error messages, it just doesn't do what I need.</p>
  
  <p>Here is the simple function that I use:</p>
  
  <pre><code>$scope.scrollTo = function (elementId) {
          console.log("element[" + angular.element(elementId) + "]");
          $location.hash(elementId);
          $timeout(function() {
              $anchorScroll();
          });
      };
  </code></pre>
  
  <p>I've also tried changing the reference to this so that instead of targetting a table row, it targets the accordion div that encloses the table, but that made no difference.  It still just jumps to the top of the page.</p>
  
  <p>Note that before I call "scrollTo", I first ensure that the accordion with the table is opened.  In any case, it still doesn't scroll correctly even after it's manually opened.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Here's a portion of the HTML that I'm trying to scroll to:</p>
  
  <pre><code>                &lt;div ng-controller="WorkflowDefsCtrl"&gt;
                  &lt;pane accordion-group heading="Workflows" is-open="accordionActiveFlags.workflowDefs" id="workflowDefs"&gt;
                      &lt;label for="workflowDefsTable"&gt;Workflow Definitions&lt;/label&gt;
                      &lt;table id="workflowDefsTable" ng-table class="table"&gt;
                          &lt;tr ng-repeat="workflowDef in sunlightConfig.workflowDefinitions | orderBy: workflowDef.order" id="workflowDef{{workflowDef.id}}"&gt;
                              &lt;td data-title="'ID'"&gt;{{workflowDef.id}}&lt;/td&gt;
                              &lt;td data-title="'Name'"&gt;{{workflowDef.name}}&lt;/td&gt;
                              &lt;td data-title="'Label'"&gt;{{workflowDef.label}}&lt;/td&gt;
                              &lt;td data-title="'Order'" class="text-right"&gt;{{workflowDef.order}}&lt;/td&gt;
                              &lt;td data-title="'Render?'"&gt;{{workflowDef.render}}&lt;/td&gt;
                              &lt;td data-title="'Query Fragment'"&gt;{{workflowDef.queryFragment}}&lt;/td&gt;
                              &lt;td data-title="'Query Order'" class="text-right"&gt;{{workflowDef.queryOrder}}&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/pane&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>The two testcases I'm trying are going to element "workflowDefs" and any of the "workflowDef{{workflowDef.id}}" elements.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I enhanced my "scrollTo" method to deal with scrolling to elements that had just become visible.  This doesn't make any difference, however.  It still just scrolls to the top no matter what.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Today I realized that a string argument to "angular.element" should be a CSS selector, not an element id, so I had to add "#" as a prefix.  This resulted in the correct element being located, but unfortunately it still had no effect on the display.  It still doesn't scroll to the element.</p>
  
  <p>My new "scrollTo" function looks like this:</p>
  
  <pre><code>    scrollTo:   function (elementId) {
          $location.hash("#" + elementId);
          $timeout(function() {
              $anchorScroll();
          });
      },
  </code></pre>