简体   繁体   English

在具有父子路由的Reactive Forms中使用patchValue

[英]Use Of patchValue in Reactive Forms with parent child routing

I have a form with parent child routing .Once user has saved info ,the code will save that data to some db. 我有一个带有父子路由的表单。一旦用户保存了信息,代码就会将该数据保存到某个数据库中。 On my home page ; 在我的主页上; I will be getting data from db in the grid form and on clicking EDIT ,my form should route user to edit the already saved form-data and update it. 我将以网格形式从db获取数据,并在单击EDIT时,我的表单应该路由用户编辑已保存的表单数据并更新它。 I have created home-page and respective routes . 我创建了主页和各自的路线。 On clicking edit my code is navigating me to my form component but getting error on clicking child component (as I have not provided route for the same). 在单击编辑时,我的代码将导航到我的表单组件,但是在单击子组件时出错(因为我没有提供相同的路由)。 Can some help me achieve this? 有人可以帮我实现这个目标吗?

I want, once user clicked on edit it should directly route user to person-info with pre-filled data and if he wishes to go to person-job ; 我想,一旦用户点击编辑,它应该直接将用户路由到具有预填充数据的人员信息,并且如果他希望去找人工作; he should be able to see data in job as well. 他也应该能够看到工作中的数据。

Existing Stackblitz 现有的Stackblitz

you can do this if you want info & job route under edit too, 如果你想要编辑信息和工作路线,你可以这样做,

const routes: Routes = [
  {path: 'home' , component:HomePageComponent},
  {
    path: 'edit/:age' , component: PersonFormComponent,
    children: [
      { path: 'info', component: PersonInfoComponent },
      { path: 'job', component: PersonJobComponent }]
  },
  {
    path: 'person',
    component: PersonFormComponent,
    children: [
      { path: 'info', component: PersonInfoComponent },
      { path: 'job', component: PersonJobComponent }]
  },
  { path: '', redirectTo: 'home', pathMatch: 'full' }
];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM