作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我们的 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
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/
我是一名优秀的程序员,十分优秀!