2

In my angular 7 code I'm trying to fetch the clientId passed in the URL. clientId will be dynamic.

localhost:4200/client/xyz

app.routing.ts

 {
  path: 'client/:clientId',
  component: AppComponent
 },

app.component.ts

constructor(private route: ActivatedRoute) { }

ngOnInit() {
   console.log(this.route.snapshot.paramMap.get('clientId'));
});

It prints null in the console

1
  • 2
    Is it Angular 6 or Angular 7? Question text and title say different. Commented May 22, 2019 at 14:06

2 Answers 2

3

You can get the route params using this method

this.route.params.subsribe(params => {
  console.log(params['clientId'])
});

or

this.activateRoute.snapshot.params['clientId']

PLease let me know if you still have problem

Sign up to request clarification or add additional context in comments.

Comments

0

Use params instead of paramMap,

console.log(this.route.snapshot.params['clientId']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.