angular - 以编程方式将 PrimeNG 元素添加到 DOM
问题描述
亲爱的,就像在 JQuery 中我们使用 #div.append('') 或 #div.append('......') 一样,是否可以通过编程方式添加 PrimeNG 元素,如输入文本、输入数字、下拉列表、多选使用一些 json 格式的 api 或其他什么?
提前致谢
解决方案
由于您已将 angular 添加为标签..
只需在您的 html 中使用 *ngFor,然后对于您放置在数组中的每个 Json 对象,您都可以生成您想要的任何元素,例如:
items: MyItem[];
<app-custom-component *ngFor="let item of items" [myItem]="item"></app-custom-component>
customComponent 像这样处理它:
@Input() myItem: MyItem;
<h1>{{myItem.title}}</h1>
<input [(ngModel)]="myItem.description" />
等等...
或者一个非常基本的例子:
items = ['one', 'two', 'three'];
<h2 *ngFor="let item of items">{{item}}</h2>
推荐阅读
- json - 来自 HTTP API 的 Chef Inspec 测试 JSON 输出
- apache - 尝试访问 OS High Sierra 上的 locahost 时出现 403 Forbidden
- pandas - 删除 pandas 中的冗余信号
- python - 用变量切片字符串,Typerror:字符串索引必须是整数
- java - Groovy 将盒装类型传递给 Jenkins,如何拆箱?
- android - RecyclerView 项目在转换到不同的屏幕并返回后更改位置
- codeigniter - 在 codeigniter 中进行 xss 过滤时删除了一些文本
- selenium - 如何使用Selenium Python提取属性图片的值
- reactjs - 如何将道具从反应类传递给formik?
- java - org.hibernate.MappingException:尝试创建新记录时的未知实体