0

I have a form which takes one parameter to construct and link a customer to a product. Now we have added another parameter to include in the URL however I can't seem to get it from the URL.

What am I doing wrong? Appreciate the help!

URL: http://localhost:4200/check/98712?Id=803

I can manage to get the first parameter out "98712" but not the Id.

In my app.module under

RouterModule.forRoot([
{ path: 'check/:cust', component: CheckComponent},

I have tried to ad Id there but it doesn't work.

In my Check component I'm taking out the customer and the Id but still the Id is empty.

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

My routes in app-routing

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


@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

Let me know if you need more code.

Fastersixth
  • 123
  • 1
  • 2
  • 13

1 Answers1

5

Your id is a query parameter, so you need to get it from queryParamMap.

this.customer = this.route.snapshot.paramMap.get('cust'); 
this.Ids = this.route.snapshot.queryParamMap.get('Id');
Kurt Hamilton
  • 12,490
  • 1
  • 24
  • 40