Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

How to pass variables in URL while getting data from backend in angular?

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...