Angular 单击“更新”后,我想导航到“更新”中的员工,我缺少什么?
我在app-routing.module.ts中添加了路由 我已在路由文件中配置路径employees/:id 在employee.ts中,我编写了一个导航到updateemployees组件的函数,但它没有发生Angular 单击“更新”后,我想导航到“更新”中的员工,我缺少什么?,angular,angular7-router,Angular,Angular7 Router,我在app-routing.module.ts中添加了路由 我已在路由文件中配置路径employees/:id 在employee.ts中,我编写了一个导航到updateemployees组件的函数,但它没有发生 const routes: Routes = [ { path: '',component:EmployeesComponent}, { path: 'employees',component:EmployeesComponent}, { path: 'employees/
const routes: Routes = [
{ path: '',component:EmployeesComponent},
{ path: 'employees',component:EmployeesComponent},
{ path: 'employees/:id',component:UpdateEmployeeComponent}
];
我在employee.component.ts中编写了一个函数
updateEmployee(id){
console.log(`Update Employee ${id}`);
this.router.navigate(['employees/', id]);
}
但我无法导航到更新员工组件。我缺少什么?试试这个:
updateEmployee(id){
console.log(`Update Employee ${id}`);
this.router.navigate(['employees', id]);
}
检查是否在html文件中添加了
。和使用
this.router.navigate(['employee',id])代码>
相对路径或
this.router.navigateByUrl('/employee/'+id)代码>
绝对路径