[Fixed] Add variable in api request angular


I have a function that take a id as parameter and do :



      this.router.navigate(['tracking/v/-- id must be here --/live'])


output of id : 4

that means i have successfully receive data, how i put this id in url here ?

      this.router.navigate(['tracking/v/ --HERE -- /live'])


You could either use template literals

this.router.navigate([`tracking/v/${id}/live`]);  // notice the back ticks `` instead of quotes ''

or string concatenation

this.router.navigate(['tracking/v/' + id + '/live']);  // here using quotes ''

You can’t mix them.

Leave a Reply

(*) Required, Your email will not be published