首页 > 解决方案 > 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

标签: angular

解决方案


我仍然不确定,如果我理解你的话(标点符号可能会有所帮助)。

为什么不使用 ngFor?

@Component({
  selector: 'my-app',
  template: `<p *ngFor="let elem of arr">I'm an element!</p>`
})
export class AppComponent  {
  arr = [1,2,3];
}

推荐阅读