2

$anchorScroll按照官方文档的示例gotoBottom,我对 angular有疑问。单击后goToBottm$anchorScroll将添加到url位置ID的 - mysite.com/tag/##ID,在第一次加载时它工作正常,但是当refershing页面ID停留在末尾时url,滚动不起作用。有想法该怎么解决这个吗?我的代码: HTML:

<button ng-click = "addRow(); gotoBottom()">add row </button>

和身份证:

<table id = "bottom">
...
</table>

gotoBottom 在我的controller

$scope.gotoBottom = function() {
  // set the location.hash to the id of
  // the element you wish to scroll to.
  $location.hash('bottom');

  // call $anchorScroll()
  $anchorScroll();
};
4

1 回答 1

-1

添加行后,您可以在“addRow”中调用此方法“gotoBottom”吗?我的猜测是它无法滚动,因为它甚至可能在添加行之前执行。

所以从你的 html 中删除 gotoBottom

<button ng-click = "addRow();">add row </button>

并将其添加到 addRow 函数

$scope.addRow = function(){
 // code for adding a row
 gotoBottom();
}
于 2016-07-07T07:19:05.203 回答