Angular 2 dynamic `template variable name`s for DynamicComponentLoader?

后端 未结 2 473
时光说笑
时光说笑 2020-12-16 10:10

TL;DR:

  • works but not dynamic
  • dynamic but doesn\'t work

Explanation:

I\'m dynamically creating

2条回答
  •  醉酒成梦
    2020-12-16 10:57

    After looking around for similar answers, it dawned on me that the default solution is actually very standard: extract a component, where you can hardcode your template variable, and generate as many instances of this component as you need with the *ngFor directive.

    I understand there may be concerns about performance, and I don't know enough about that to comment either way (who knows, it may end up being faster), but IMO it should definitely be the first solution to be envisioned.

    And the DynamicComponentLoader mentionned in Eric Martinez answer seems to be gone from Angular 5 anyway (couldn't find it in the docs).

提交回复
热议问题