AngularViewportScroller在Angular14版本中不起作用。
创始人
2024-10-29 22:00:51
0

在Angular 14中,ViewportScroller的使用方式略有不同。在使用ViewportScroller.scrollToPosition()之前,需要先在构造函数中声明ViewportScroller依赖注入。以下是示例代码:

import { Component, OnInit } from '@angular/core'; import { ViewportScroller } from '@angular/common';

@Component({ selector: 'app-my-component', templateUrl: './my-component.component.html', styleUrls: ['./my-component.component.css'] }) export class MyComponent implements OnInit {

constructor(private viewportScroller: ViewportScroller) { }

ngOnInit() { }

scrollToTop() { this.viewportScroller.scrollToPosition([0, 0]); }

}

在上面的示例中,ViewportScroller注入到了组件的构造函数中。scrollToTop()方法会使用ViewportScroller.scrollToPosition()方法来将滚动条的位置滚动到顶部。

请注意,如果要使用scrollToPosition()方法来滚动到一个元素,可以将ViewportScroller作为依赖注入,并使用scrollToAnchor()方法来实现。

相关内容

热门资讯

据权威媒体报道!wepoker... 据权威媒体报道!wepoker买钻石有用吗,德普之星透视辅助软件,确实是真的有挂(有挂辅助)1、进入...
一分钟带你了解!wepoker... 一分钟带你了解!wepoker辅助真的假的,pokemmo手机脚本辅助器,都是是真的有挂(揭秘有挂)...
玩家必用!wepoker辅助器... 玩家必用!wepoker辅助器是真的吗,竞技联盟辅助插件,竟然真的有挂(有挂存在)1、进入游戏-大厅...
据相关数据显示!wepoker... 据相关数据显示!wepoker私局辅助,德扑之星辅助器app,总是真的是有挂(有挂透明挂)运德扑之星...
重大通报!德普之星辅助工具如何... 重大通报!德普之星辅助工具如何打开,wepoker私人局辅助挂,总是真的有挂(确实有挂)1、免费脚本...
反观!wepoker怎么设置盖... 反观!wepoker怎么设置盖牌,德普之星辅助工具如何设置,真是是真的有挂(有挂教程)1、操作简单,...
一分钟揭秘!aapoker能控... 一分钟揭秘!aapoker能控制牌吗,wepoker俱乐部辅助,竟然真的是有挂(真的有挂)1、让任何...
2026版辅助挂!sohoo开... 2026版辅助挂!sohoo开挂辅助,德普之星辅助软件,一直是有挂(确实有挂)1)德普之星辅助软件辅...
技巧知识分享!pokemomo... 技巧知识分享!pokemomo辅助工具,aapoker透视脚本入口,原来是真的有挂(有挂头条)1、操...
2026版方法!we poke... 2026版方法!we poker辅助器v3.3,德扑之星有透视辅助吗,其实是有挂(有挂秘笈)1、任何...