Angular Ionic 4路由器链路和查询参数不工作
我一直在尝试我在这里找到的不同解决方案。然而,这些都不起作用。我能够生成带有参数的链接,但仍然无法在另一个组件中获得它。这是我的密码: app-routing.module:Angular Ionic 4路由器链路和查询参数不工作,angular,ionic-framework,routing,ionic4,Angular,Ionic Framework,Routing,Ionic4,我一直在尝试我在这里找到的不同解决方案。然而,这些都不起作用。我能够生成带有参数的链接,但仍然无法在另一个组件中获得它。这是我的密码: app-routing.module: { path: 'branch', loadChildren: './branch/branch.module#BranchPageModule' } choosePage.html: <ion-col> <a class="flex" [routerLink]= "['/branch']
{ path: 'branch', loadChildren: './branch/branch.module#BranchPageModule' }
choosePage.html:
<ion-col>
<a class="flex" [routerLink]= "['/branch']" [queryParams]="{ id: '17'}" routerDirection="forward">
<!-- something here -->
</a>
</ion-col>
branch.page.html:
{{ brand }}
可能遗漏了什么??即使在
console.log
have nothing中,在收到数据之前,您也无法应用过滤器,从外观上看,您根本不需要应用过滤器,因为您可以直接访问参数
ngOnInit() {
this.route.queryParams
.subscribe(params => {
console.log(params);
this.brand = params.id;
console.log(this.brand);
});
}
否则,您将需要确保已将routermodule也导入到子页面组件中。这是一个使用上面代码的工作闪电战您是否尝试过不使用过滤功能?我想您可能需要先从subscribe函数接收值,然后才能对其执行任何操作查询参数是否至少正确地显示在地址栏中?@chrismclarkeyes it do
http://localhost:8100/branch?id=17
,是的,我已移除过滤器,结果相同。好的,很高兴知道。您还可以添加您的branch.page.module.ts,因为这是延迟加载的。可能在那里的某个地方也有线索。
ngOnInit() {
this.route.queryParams
.subscribe(params => {
console.log(params);
this.brand = params.id;
console.log(this.brand);
});
}