4

I basically want to create and add a component to the DOM programatically at runtime. Note a similar question was posted here but it refers to Angular 1, this question is for Angular 2.

Community
  • 1
  • 1
Dandan
  • 519
  • 2
  • 9

1 Answers1

0

You can use dynamic component from angular2_components: https://github.com/dart-lang/angular2_components/tree/master/lib/src/components/dynamic_component

It allow you to pass [Type] of a component and it will do the job.

rkj
  • 8,787
  • 2
  • 29
  • 35
  • 2
    But dynamic component still needs to be included (and thus compiled) in my template. In my case, I'd like to replace some HTML retrieved from an external (safe) source with Angular components. – Dandan Apr 14 '17 at 18:19
  • Do you mean like getting something like `'{{otherVariable}}'` as a string, parsing it and adding it to the DOM? – filiph Apr 28 '17 at 23:59
  • 1
    I think that would require shipping compiler and Anulgar Dart doesn't currently do it out of the box. – rkj May 06 '17 at 04:15