如何在URL中传递变量

时间:2019-11-14 06:14:31

标签: angularjs typescript angular-router

我想将projectIdurl一起传递。我该如何实现?

    var projectId = e.data.id;
    var url = `/pages/project_details/,`projectId`,/Ongoing`;
    this.router.navigateByUrl(url).then(e =>{
      if(e){
        console.log('routed');
      }else{
        console.log('not routed');
      }
    });

3 个答案:

答案 0 :(得分:1)

您可以这样使用。

var projectId = e.data.id;
var url = `/pages/project_details/${projectId}/Ongoing`;
console.log(url);

答案 1 :(得分:1)

尝试一下:

var projectId = 12345; // example project id
var url = '/pages/project_details/'+projectId+'/Ongoing';

print(url)
// output: /pages/project_details/12345/Ongoing

答案 2 :(得分:1)

如果您使用的是Angular 7或更高版本,则可以使用以下标准的打字稿

const projectId = e.data.id;;
const url = '/pages/project_details/' + projectId + '/Ongoing'; 
console.log(url )