0

Hi I have a directive as below,

@Directive({
      selector: '[changeColor]',
      exportAs:'changeColor' 
    })
    export class ColorDirective {
@Input('mfData') public inputData: any[] = [];
        constructor(elem: ElementRef, renderer: Renderer2) {
           renderer.setStyle(elem.nativeElement, 'color', 'red');
console.log(this.inputData, 'inputData');
        }
    }

And use it as below:

<h1 #x=changeColor>Hello</h1>

What if my x value is dynamically generating (inside ngFor). How can add an index infront or after x, so that my x value will be unique? like below

<h1 #x1=changeColor>Hello1</h1>
<h1 #x2=changeColor>Hello2</h1>
....
<h1 #xn=changeColor>Hellon</h1>

Please help me guys on this.. TIA

Updated HTML with @Input variable

<div class="col-12 u-grey-container table--section u-margin-bottom-8" *ngFor="let color of colorList;let ndx = index">

 <table class="table table-striped" [mfData]="color.list" #main="changeColor" *ngIf="color.list" (mfSelectedEntities)="selectedRecords($event, schedule)">
<thead> ... </thead>
<tbody>
<template let-item ngFor [ngForOf]="main.data" let-ndx="index">
...
</tbdoy>
</table>
</div>
chewi
  • 159
  • 2
  • 3
  • 16

0 Answers0