【问题标题】:Angular $anchorScroll ID remains in the url and not working after refreshAngular $anchorScroll ID 保留在 url 中,刷新后不起作用
【发布时间】:2017-07-19 02:11:09
【问题描述】:

我对 Angular $anchorScroll 有疑问,请参阅 offical doc'sgotoBottom 示例。单击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();
};

【问题讨论】:

  • 跟文档一样,还要贴吗?
  • 请。因为有些东西不适合你。
  • 发帖,如果有更多需要我也会发帖。
  • @Chinni 发布,该功能正在运行,只是无法摆脱我网址末尾的##。
  • 所以你不想要那个##ID

标签: angularjs anchor-scroll


【解决方案1】:

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

所以从你的 html 中删除 gotoBottom

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

并将其添加到 addRow 函数中

$scope.addRow = function(){
 // code for adding a row
 gotoBottom();
}

【讨论】:

  • 尝试并发布结果。
  • - 不起作用,'##ID' 保留在 url 的末尾。
  • 你能在这里发一个 plunker 或一个 sn-p 吗?
  • 和文档一样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-20
  • 2015-07-21
  • 1970-01-01
  • 2020-06-20
  • 2021-03-19
  • 1970-01-01
相关资源
最近更新 更多