AngularDart中的滚动位置恢复
创始人
2024-10-24 00:31:49
0

在AngularDart中,可以使用ScrollPositionRestorer类来恢复滚动位置。下面是一个包含代码示例的解决方法:

首先,在需要恢复滚动位置的组件中,添加一个ScrollPositionRestorer的依赖注入:

import 'package:angular/angular.dart';

@Component(
  selector: 'my-component',
  template: '''
    
''', directives: [coreDirectives], ) class MyComponent implements AfterViewInit { final ScrollPositionRestorer _scrollPositionRestorer; @ViewChild('container') ElementRef container; MyComponent(this._scrollPositionRestorer); @override void ngAfterViewInit() { _scrollPositionRestorer.registerElement(container.nativeElement); } }

然后,在根组件中,添加一个ScrollPositionRestorer实例,并在适当的时候调用restoreScrollPosition方法来恢复滚动位置:

import 'package:angular/angular.dart';

@Component(
  selector: 'my-app',
  template: '''
    
  ''',
  directives: [routerDirectives],
)
class AppComponent implements AfterViewInit {
  final ScrollPositionRestorer _scrollPositionRestorer;

  AppComponent(this._scrollPositionRestorer);

  @override
  void ngAfterViewInit() {
    _scrollPositionRestorer.restoreScrollPosition();
  }
}

这样,当切换组件或路由时,滚动位置会自动恢复到之前的位置。注意,为了使滚动位置能够正确地恢复,要确保每个组件都有一个唯一的标识符(例如,使用路由参数)以便进行区分。

相关内容

热门资讯

透视规律!aapoker辅助软... 透视规律!aapoker辅助软件合法吗(透视)透视脚本入口(总是真的有挂)aapoker辅助软件合法...
透视规律!aapoker辅助器... 透视规律!aapoker辅助器是真的吗(透视)透视方法(真是真的有挂)aapoker辅助器是真的吗软...
透视能赢!aapoker俱乐部... 透视能赢!aapoker俱乐部靠谱吗(透视)透视脚本(确实真的有挂);1、玩家可以在aapoker俱...
透视讲解!aapoker辅助器... 透视讲解!aapoker辅助器是真的吗(透视)免费透视脚本(真是有挂);1、打开软件启动之后找到中间...
透视好友!aapoker怎么选... 透视好友!aapoker怎么选牌(透视)透视软件(本来是真的有挂)1、起透看视 aapoker怎么选...
透视辅助!aapoker俱乐部... 透视辅助!aapoker俱乐部靠谱吗(透视)透视脚本下载(确实真的有挂);1、该软件可以轻松地帮助玩...
透视玄学!aapoker能控制... 透视玄学!aapoker能控制牌吗(透视)透视脚本(原来真的是有挂)1)aapoker能控制牌吗辅助...
透视教程!aapoker脚本怎... 透视教程!aapoker脚本怎么用(透视)透视脚本(总是有挂)1、aapoker脚本怎么用系统规律教...
透视中牌率!aa poker辅... 透视中牌率!aa poker辅助(透视)万能辅助器(好像是真的有挂);1、玩家可以在aa poker...
透视游戏!aapoker怎么选... 透视游戏!aapoker怎么选牌(透视)透视脚本入口(本来有挂)1、aapoker怎么选牌ai辅助优...