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.

1

1 Answer 1

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'); 
Sign up to request clarification or add additional context in comments.

1 Comment

You are a hero! I was blindsided here, totally missed that. Will mark as answer as soon as I can. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.