小编Joc*_*ado的帖子

Angular 4路由参数捕获为未定义

我是Angular的新手.我正在尝试编辑localhost:4200/edit /:id中的项目,但我无法捕获:id param从中获取相应的数字(它应该是类似localhost:4200/edit/7,例如).当我将params.id输出到控制台时,它总是显示"未定义".

我的app.module.ts

...
import { RouterModule} from '@angular/router';

const routes = [
{ path: '', component: NavigateComponent },
{ path: 'field', component: FieldComponent },
{ path: 'book', component: MaterialFullComponent, children: [
  { path: '', redirectTo: '', pathMatch: 'full' },
  { path: ':id_book', component: MaterialFullComponent }
] },
{ path: 'edit', component: MaterialEditComponent, children: [
  { path: '', redirectTo: '', pathMatch: 'full' },
  { path: 'new', component: MaterialEditComponent },
  { path: ':id', component: MaterialEditComponent }
] },
{ path: …
Run Code Online (Sandbox Code Playgroud)

parameters router angular

1
推荐指数
1
解决办法
8201
查看次数

标签 统计

angular ×1

parameters ×1

router ×1