从组件获取值以在锚点内的 queryParams 中查看
我正在一个组件页面之一上应用全局导航。
myComponent
export class MyComponent implements OnInit {
sampleId: number;
ngOnInit() {
try {
this.route.queryParams.subscribe(params => {
this.sampleId = params['sampleId'];
this.router.navigate(["/samples"], { queryParams: { id: this.sampleId} });
})
}
}
}
App-rounting.ts
const routes: Routes = [
{ path: 'samples', component: MyComponentViewComponent }]
视图
<li class="style-cls" [routerLinkActive]="['link-active']">
<a [routerLink]="['/samples']" [queryParams]="{id: this.sampleId }">Samples</a>
</li>
我遇到了一个错误来使用锚标签显示导航。在Queryparams中,如何获得组件中分配的ID值,以便可以导航。
I am applying global navigation on one of my component page.
MyComponent
export class MyComponent implements OnInit {
sampleId: number;
ngOnInit() {
try {
this.route.queryParams.subscribe(params => {
this.sampleId = params['sampleId'];
this.router.navigate(["/samples"], { queryParams: { id: this.sampleId} });
})
}
}
}
app-rounting.ts
const routes: Routes = [
{ path: 'samples', component: MyComponentViewComponent }]
View
<li class="style-cls" [routerLinkActive]="['link-active']">
<a [routerLink]="['/samples']" [queryParams]="{id: this.sampleId }">Samples</a>
</li>
I am getting an error to display the navigation using anchor tag. In queryparams, how can I get the value of id which is assigned in component so that I can navigate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论