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.
1 Answer
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.
3 Comments
Dandan
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.
filiph
Do you mean like getting something like
'<material-button [disabled]="someVariable">{{otherVariable}}</material-button>' as a string, parsing it and adding it to the DOM?rkj
I think that would require shipping compiler and Anulgar Dart doesn't currently do it out of the box.