简体   繁体   English

ScrollIntoView()锁定滚动Angular4

[英]ScrollIntoView() locks scroll Angular4

I am new to Angular. 我是Angular的新手。 I have a component where I want the page to scroll down to the first error when the user attempts to save invalid inputs. 我有一个组件,当用户尝试保存无效输入时,我希望页面向下滚动到第一个错误。 The code I am using is: 我使用的代码是:

const element = this.renderer.selectRootElement('#input1');
            element.scrollIntoView({block: 'center'}); 

The page scrolls to the error just fine, but the problem is that it then locks the scroll. 页面滚动到错误就好了,但问题是它随后锁定了滚动。 Any attempt to scroll away from the error brings me right back to the same place, even if the error has been corrected. 即使错误已得到纠正,任何试图消除错误的尝试都会使我回到同一位置。 How can I "release" the scroll once the page scrolls to the first error? 页面滚动到第一个错误后,如何“释放”滚动? Any help will be much appreciated. 任何帮助都感激不尽。

难道是您的代码被断断续续地触发了,也许是在ngOnChange中触发了,并且您的错误标志从未得到解决?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM