0

I am building a project with angular 2 and struggling with something here.

The project in a form, and I would like to have dynamic HTML content to display the form. The content would be relative to the user visiting the form.

Let's say the visitor of id '4' is visiting the app and we have developed a custom template of id '4' for him, the custom template would be displayed, otherwise we will just display the default template.

If anyone could help.

Thank you.

1 Answers1

0

You can use

  • [innerHTML]="someHtml" to add plain HTML (no Angular components, directives, bindings)

  • ViewContainerRef.createComponent to add/remove components dynamically (See Angular 2 dynamic tabs with user-click chosen components for an example)

  • *ngIf="..." to show/hide parts of the template, depending on a condition

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Thanks a lot. If I dynamically create a component with the Component Factory, can this new Component use the logic of his 'parent' component (by maybe extending it) ? – Rodolphe Nivelet Jan 13 '17 at 09:33
  • Support for inheritance with components was added recently, but I don't know how well it works. I haven't tried it. – Günter Zöchbauer Jan 13 '17 at 09:36