在访问之前我解决一个用户帐户片段我的用户页面:
APP-routing.component.ts
{ path: 'users/:id', component: UserComponent, resolve: {user: UsersService}, children: [ {path: '', pathMatch: 'full', redirectTo: 'account'}, {path: 'account', component: UserAccountComponent}, {path: 'sites', component: UserSitesComponent} ] }
users.service.ts
resolve(route: ActivatedRouteSnapshot, r: RouterStateSnapshot) { return this.getUser(route.params['id']); }
用户account.component.ts
ngOnInit() { this.route.parent.data.subscribe(data => { this.user = data['user']; // Initialize the form and its validators this.initForm(); }); }
在用户帐户组件中,我可以保存或重置表单.在这两种情况下,我都想更新组件的用户并重置表单和验证器.理想情况下,它会再次触发订阅.
知道如何手动触发旋转变压器吗?
(我曾经重新导航到与最后一个片段模拟一个随机数的相同路径,但是由于我将用户页面分解为父/子路径,因此当最后一个片段发生变化时,不再调用父级中的解析器)