class SimpleComponent {
}
var string = 'SimpleComponent';
bootstrapComponents.push(string); // This should be 'SimpleComponent' class and not a string value.
如何从typescript中的字符串值传递类对象?
答案 0 :(得分:1)
将类名添加为键
var classPointer={'SimpleComponent':SimpleComponent};
bootstrapComponents.push(classPointer[string]);
答案 1 :(得分:0)
据我所知,angular2的模块化概念不是将类存储在数组或对象中并推送它们,而是导出类并将它们导入其他地方。相反,将应用程序划分为模块并通过路由器加载它们。除非通过lazyload指定,否则未使用的模块及其各自的组件将仅在需要时加载。