1
public getQuestionsById(qid:number): Observable<Questions>{
 return this.httpClient.get<Questions> 
  ('http://localhost:9090/angular/questions/${qid}');
  
}

Here, I want to concatenate the "qid" variable value in this URL. What should be the right format for that?

2 Answers 2

3

You just have to use Template literals for that. Check the basics you are just using wrong operator. please not use single quote here, use backquot for that.

public getQuestionsById(qid:number): Observable<Questions>{
    return this.httpClient.get<Questions>(`http://localhost:9090/angular/questions/${qid}`);
     
   }

Best of luck :)

link : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

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

Comments

1

I personally do this :

public getQuestionsById(qid:number): Observable<Questions>{
    return this.httpClient.get<Questions>("http://localhost:9090/angular/questions/" + qid);  
   }

Also a quick tip, instead of writing that URL in every single Service file, add a variable in the environment file, then you can import it anywhere you need it
(in case you are using this in more Services, of course).

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.