使用按钮如何滚动到 angular 中选定的 div 6

using button how to Scroll to selected div in angular 6

您好,如果我单击按钮,它应该滚动到选中的按钮,我在此使用 Angular6 div。为此,我使用了 npm install ng2-scroll-to --save 插件,但按钮选择器不起作用,请帮助我完成此操作。如果有任何替代解决方案也请告诉我。

<a scrollTo href="#main-section">Scroll to main section</a>
        <button scrollTo scrollTargetSelector="#test-section">Scroll to test section</button >
        <button scrollTo scrollableElementSelector="#container" scrollYTarget="0">Go top</button >
        <!-- Further content here -->
        <div id="container">
            <section id="main-section">Bla bla bla</section>
            <section id="test-section">Bla bla bla</section>
        <div>

您必须将 ScroolModule 导入应用程序模块

// app.module.ts
import {ScrollToModule} from 'ng2-scroll-to';

@NgModule({
    imports: [
         ....,
        ScrollToModule.forRoot(),
        ]
})

之后应该就没问题了。