0

I want to call this backend URL to receive user profile data

/users/:userId/profile

where :userId will be an actual number for the ID.

What is the syntax to inject the userId value to the URL before sending the request?

3
  • You can refer - techiediaries.com/angular-by-example-httpclient-get for http get call. hope it helps. Commented May 30, 2019 at 4:33
  • You can pass the param as array in the routerlink. Also you can opt the way @Mohammad has answered below. Commented May 30, 2019 at 6:11
  • Thanks. But I am not doing router.navigate, I am doing something like httpClient.put Commented May 30, 2019 at 13:36

2 Answers 2

1

One way ( using typescript ) is to use a template string

`/users/${this.userId}/profile`

The template is surrounded by the backticks ( `` ).
The string inside the backticks can evaluate expressions when they're inside a ${...}.

The string above is the same as typing:

'/users/' + this.userId + '/profile'
Sign up to request clarification or add additional context in comments.

Comments

0

You can simply concatenate it like string concatenation.

http.get('/users'/+this.userId+'/profile').then();

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.