我想在单击 Angular 7 中的按钮时滚动到特定的 div,下面是我正在使用的代码,但它在 stackblitz 中工作,但在我的项目中使用时显示错误。 “无法读取未定义的属性‘scrollIntoView’”。
https://stackblitz.com/edit/angular-scroll-local-variable?file=src%2Fapp%2Fscroll.component.ts
试试这个链接: https://stackblitz.com/edit/angular-scroll-local-variable-ja96uz ?file=src%2Fapp%2Fapp.component.html
<button (click)="scroll(target)"></button>
<div #target>Your target</div>
并在组件中:
scroll(el) {
el.scrollIntoView();
}
原文由 mani singh 发布,翻译遵循 CC BY-SA 4.0 许可协议
尝试提供 scrollToAnchor 方法的角度 ViewportScroller 服务
滚动.html
滚动.ts
示例: https://stackblitz.com/edit/angular-scroll-local-variable-99hwvo