英文:
[Angular Application]: Navigate to another Page and Scroll to a particular section
问题
我们可以通过添加带有ID的锚元素,并将该ID粘贴为链接中的片段,从而使页面滚动到该部分。
但是,这里的挑战是,如果我们在同一页中添加片段和锚点,它会滚动到该部分。
但我正在导航到不同的页面,并且在导航时添加了片段,但它不会滚动到该部分。
原因是由于子组件的懒加载。在导航时,这些组件尚不可用,这就是不滚动的原因。
一种解决方法是在ngAfterViewInit中添加一些JavaScript功能,比如ScrollIntoView
。但是,如果可能的话,希望找到其他方法。
将所有这些词语放在一行中点击按钮后,在Angular应用程序中导航到另一页并滚动到特定部分。
英文:
We can add a anchor element with id and by pasting the id as fragment in the link it will scroll to that section.
But the challenge here is, If we add fragment and anchor present in same page it is going to scroll.
But I am navigating to different page and fragment is being added while navigating, but is not scrolling to that section.
Reason is due lazy loading of child components. When Navigating, the components are not available yet, and that's reason not scrolling.
A workaround is to add some javascript functionality in ngAfterViewInit like ScrollIntoView
. But Looking for any other approaches if possible.
Putting all these words in line On Click of Button, Navigate to another page and scroll to particular section in Angular Application
答案1
得分: 1
使用Router.Navigate
非常简单。您可以使用要导航到的元素的ID
和fragment。
英文:
Its pretty straightforward with Router.Navigate. you can use the fragment with the ID
of the element you want to navigate to.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论