最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - Angular: Maintaining a map or dictionary of component types - Stack Overflow

programmeradmin7浏览0评论

I have come over to the community to find some wisdom. I have currently migrated my project from angular 12 to angular 19.

To that end I want to maintain a map or dictionary of components which I would use to render these components dynamically via a service which gets the type of the component based on the string key provided and renders it via view container ref.

const componentMap =  {
"comp1": Component1,
"comp2": Component2,
}

But in keeping the map of components I run into obvious circular dependency DI/compile time issues. It worked fine with angular 12 and I know its poor code. So now I was scouring the web for maintaining a map/dictionary of component types/ component references which can then be used with viewContainerRef to render component. I could not find any best practises for doing that. Hence I am here to ask for help from the community and gain some knowledge in the process. Thanks for the help in advance.

发布评论

评论列表(0)

  1. 暂无评论