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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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?
I think that would require shipping compiler and Anulgar Dart doesn't currently do it out of the box.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.