gpt4 book ai didi

Angular 4 订阅 paramMap 不适用于 child socket

转载 作者:行者123 更新时间:2023-12-01 13:31:18 26 4
gpt4 key购买 nike

在我们的 Angular 4 App我们有带有契约(Contract)列表的下拉列表。

一旦用户选择合约,我们就会触发 router.navigate , 使用选定的 contractId 更改 url我们做了一个 http request用它。

其实很简单:
this.activatedRoute.paramMap.subscribe(...request with contractId...)
这适用于平坦的路线。

但是在有 child 的路线上它不起作用,例如对于这条路线:

export const customerRoutes: Routes = [
{
path: ":contractId/Customers",
component: CustomersComponent,
children: [
{ path: "", redirectTo: "Children", pathMatch: "full" },
{ path: "Children", component: ChildrenComponent }
]
}
];

上面的路线给了我以下网址: http://localhost:4033/20917/Customers/Children
现在让我们假设我想在 DropDown 中选择一个新契约(Contract)......

...那是 onChange下拉列表:
public onChange(contract: Contract): void {
this.router.navigate([contract.id, window.location.pathname.split("/")[3]]);
}

哪里 window.location.pathname.split("/")[3]给我: 客户

网址更改为 http://localhost:4033/33444/Customers/Children ,但是订阅没有被点击。为什么?

最佳答案

要监视父组件的更改事件,我们需要显式调用:
this.activatedRoute.parent.paramMap.subscribe(...request with contractId...)
这不在文档中,我已经为此创建了一个请求:https://github.com/angular/angular/issues/18862

关于Angular 4 订阅 paramMap 不适用于 child socket ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45843127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com