【发布时间】:2018-06-28 18:58:28
【问题描述】:
我正在使用 A6 路由器在 /new 路由上渲染 3 个组件。我也在使用Angular-material 并使用sidenav 组件。我的 parentComponent 是主要内容区域,而 childComponent 是抽屉内容。
{
path: 'new',
children: [
{
path: '',
component: ParentComponent
},
{
path: '',
component: SiblingComponent,
outlet: 'nav',
children: [
{
path: '',
component: ChildComponent
}
]
}
]
}
子组件html
<div class="new-event-side-nav">
<mat-nav-list>
<a mat-list-item>
<span>Some Details</span>
</a>
<a mat-list-item [href]="otherDetail">
<span>Other Details</span>
</a>
</mat-nav-list>
</div>
父组件
<mat-card>
<div id="some_detail">
<p>Some Content</p>
</div>
<div id="other_detail">
<p>Other Content</p>
</div>
</mat-card>
我可以使用
在我的子组件中提取两个 div 的 IDotherDetail = document.getElementById('other_detail');
并将其注入到我的子组件的 html 中。但是点击它并没有向下滚动到元素,我得到一个 404。此外,我的网址从 /new 更改为 /%5Bobject%20HTMLDivElement%5D
我是 Angular 6 中滚动到元素的新手。任何人都有使用子元素的 sidenav 滚动到不同元素的经验?
【问题讨论】:
标签: angular angular-material angular-routing angular6