Create an array of VisualTextDivComponent
for the array of objects. Pass this array to ngFor
. Then pass each element of the array to your app-visual-text-div
component as follows:
<div #visualTextDiv class = "visual_text" [ngStyle]=setStyles()> <div *ngFor="let lineCounter of visualDivArray"> <app-visual-text-div [curLineCounter]="lineCounter"></app-visual-text-div> </div> </div>
curLineCounter
or some better name, is a variable in the app-visual-text-div
component.
AppVisualTextDiv.ts
import { Component, Input } from '@angular/core'; @Component({ selector: 'app-visual-text-div', templateUrl: './AppVisualTextDiv.html' }) export class AppVisualTextDiv{ @Input() curLineCounter: { 'id': number, 'someValue': string, }; }
AppVisualTextDiv.html
<div id="{{curLineCounter.id}}"> <span>{{curLineCounter.someValue}}</span> </div>
source share