简体   繁体   中英

Dynamic content in Angular 2 app

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM