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()方法来实现。

相关内容

热门资讯

一分钟了解!hhpoker可以... 一分钟了解!hhpoker可以开挂吗,wepoker祈福有用吗,竟然有挂(有挂秘诀)1、不需要AI权...
玩家必看教程!pokemmo脚... 玩家必看教程!pokemmo脚本手机版,智星菠萝可以辅助吗,总是真的是有挂(有挂解密)1、透视辅助软...
每日必备!wpk是真的还是假的... 每日必备!wpk是真的还是假的,wepoker辅助软件价格,本来存在有挂(有挂讲解)1、下载好wep...
玩家必备科普!wepoker手... 玩家必备科普!wepoker手机插件,hhpkoer辅助器视频,原来有挂(有挂辅助)亲,关键说明,透...
最新技巧!wepoker好友助... 最新技巧!wepoker好友助力码,pokemmo免费脚本,一直是真的有挂(讲解有挂)最新技巧!we...
程序员教你!hhpoker真能... 程序员教你!hhpoker真能买到挂吗,wepoker脚本,真是是真的有挂(有挂技巧)1、玩家可以在...
推荐十款!hhpoker辅助软... 推荐十款!hhpoker辅助软件下载,wepoker辅助是真的假的,真是真的是有挂(有挂方略)1、完...
玩家必备科技!wepoker透... 玩家必备科技!wepoker透视脚本免费使用视频,wepoker透视有用吗,本来真的是有挂(有挂神器...
必知教程!wepoker透视脚... 必知教程!wepoker透视脚本免费使用视频,wepoker透视有用吗,一贯真的是有挂(了解有挂)1...
最新研发!wepoker辅助器... 最新研发!wepoker辅助器下载,xpoker辅助怎么用,竟然存在有挂(有挂解密)1、最新研发!w...