简体   繁体   English

Angular 2应用程序中的动态内容

[英]Dynamic content in Angular 2 app

I am building a project with angular 2 and struggling with something here. 我正在构建一个角度为2的项目,并且在这里遇到了一些困难。

The project in a form, and I would like to have dynamic HTML content to display the form. 该项目以表单形式存在,我想拥有动态HTML内容来显示表单。 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. 假设ID为'4'的访问者正在访问该应用,并且我们已经为他开发了ID为'4'的自定义模板,该自定义模板将会显示,否则我们将只显示默认模板。

If anyone could help. 如果有人可以帮助。

Thank you. 谢谢。

You can use 您可以使用

  • [innerHTML]="someHtml" to add plain HTML (no Angular components, directives, bindings) [innerHTML]="someHtml"添加纯HTML(无Angular组件,指令,绑定)

  • ViewContainerRef.createComponent to add/remove components dynamically (See Angular 2 dynamic tabs with user-click chosen components for an example) ViewContainerRef.createComponent以动态添加/删除组件(有关示例,请参见带有用户单击所选组件的Angular 2动态选项卡

  • *ngIf="..." to show/hide parts of the template, depending on a condition *ngIf="..."根据条件显示/隐藏模板的某些部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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