字符串到打字稿类名称

时间:2018-12-24 05:40:20

标签: javascript angular string typescript

我正在动态生成打字稿代码。所以我有这个:

let data = {
  path: 'home',
  component: '${homeComponentName}',
  children:[]
};

let homeComponentName = 'HomeComponent'
let tpl= eval('`' + JSON.stringify(data) + '`')   

现在我的结果是:

{
  path: 'home',
  component: 'HomeComponent',
  children:[]
}, 

但是我需要删除“ HomeComponent”中的引号。预期结果是:

{
  path: 'home',
  component: HomeComponent,
  children:[]
}, 

1 个答案:

答案 0 :(得分:0)

我想您尝试执行的操作是不可能的,因为不仅需要更新其值,而且还需要在顶部导入该组件的路径,

相关问题