簡體   English   中英

字符串值的打字稿+ angular2通過類

[英]typescript + angular2 pass class from a string value

class SimpleComponent {

}


var string = 'SimpleComponent';

bootstrapComponents.push(string); // This should be 'SimpleComponent' class and not a string value.

如何從打字稿中的字符串值傳遞類對象?

將類名添加為鍵

var classPointer={'SimpleComponent':SimpleComponent};

 bootstrapComponents.push(classPointer[string]);

據我所知,angular2的模塊化概念不是將類存儲在數組或對象中並將其推向四周,而是將類導出並將其導入其他地方。 相反,將您的應用程序細分為模塊,然后通過路由器加載它們。 除非通過lazyload另行指定,否則未使用的模塊及其各自的組件僅在需要時才加載。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM