小编Fas*_*xth的帖子

从 URL 获取两个参数

我有一个表单,它采用一个参数来构建并将客户链接到产品。现在我们添加了另一个参数以包含在 URL 中,但是我似乎无法从 URL 中获取它。

我究竟做错了什么?感谢帮助!

网址:http://localhost:4200/check/98712?Id=803

我可以设法从“98712”中获取第一个参数,但不能获取 Id。

在我的 app.module 下

RouterModule.forRoot([
{ path: 'check/:cust', component: CheckComponent},
Run Code Online (Sandbox Code Playgroud)

我试图在那里添加 ID,但它不起作用。

在我的 Check 组件中,我取出了客户和 Id,但 Id 仍然是空的。

this.customer = this.route.snapshot.paramMap.get('cust'); 
this.Ids = this.route.snapshot.paramMap.get('Id'); //Ids since it could be several, hence the add of Id in the URL
Run Code Online (Sandbox Code Playgroud)

我在 app-routing 中的路线

const routes: Routes = [
  { path: '', redirectTo: 'ms', pathMatch: 'full' },
  { path: 'ms', component: CheckComponent },
];


@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

标签 统计

angular ×1

typescript ×1