angular - Angular custom directive repeats the element in angular 5
问题描述
I want to build an directive in that directive an array of elements will be there and by binding that directive on any element the element should repeat the number of times the array has in suppose if array has 3 elements by binding directive to element element will repeat 3 times please help and provide basic idea because i am beginner to it i want to acheive this in angular 5
解决方案
我仍然不确定,如果我理解你的话(标点符号可能会有所帮助)。
为什么不使用 ngFor?
@Component({
selector: 'my-app',
template: `<p *ngFor="let elem of arr">I'm an element!</p>`
})
export class AppComponent {
arr = [1,2,3];
}
推荐阅读
- javascript - 配置 Jest 以支持 Typescript (NodeJs)
- swift - 一种方法如何同时被称为乘法?
- mysql - 使用第一个查询的结果作为第二个查询中的变量触发
- android-studio - 在 Android Studo 中添加文本框
- postgresql - Postgres 在文本字段中转义单引号和双引号
- c# - 无法从 .net core Web 应用程序调用 .net core 进程
- salesforce - 当列中存在重复值时添加唯一索引
- python-3.x - 如何防止 QTableWidget 中没有选择?
- java - Ormlite 保存错误的日期,具体取决于一天中的时间
- python - 将xml转json结构后增加json中某个节点的值