angular - Repeat HTML element multiple times using ngFor based on a number -
how use *ngfor
repeat html element multiple times?
for eg: if have member variable assigned 20. how use *ngfor directive make div repeat 20 times?
you use following:
@component({ (...) template: ` <div *ngfor="let of arr(num).fill(1)"></div> ` }) export class somecomponent { arr = array; //array type captured in variable num:number = 20; }
or implement custom pipe:
@pipe({ name: 'fill' }) export class fillpipe implements pipetransform { transform(value) { return (new array(value)).fill(1); } } @component({ (...) template: ` <div *ngfor="let of num | fill"></div> `, pipes: [ fillpipe ] }) export class somecomponent { arr:array; num:number = 20; }
Comments
Post a Comment