Condition *ngIf for applying a class

Asked

Viewed 131 times

0

I am trying to apply a class when my element is clicked, but it is within two *ngFor.

I thought to do with multidimensional array but apparently this is not the correct form because it is applying the class in several elements.

I tried something like:

<div *ngFor="let tabelaAnuncioContas of sortedData; let a = index">

   <tr *ngFor="let anuncio of tabelaAnuncioContas.data[0].anuncio; let i = index">
       <td><img [class.zoomImg]="zoomImg[a][i] == true" (click)="zoomImg[a][i]= !zoomImg[a][i]" [src]="anuncio.produto.foto_prin_1"></td>
  </tr>

</div>

TS:

zoomImg:[][] = [[]];

When you have more than one element in the sorted array:

Cannot read Property '0' of Undefined

When you have only one element in the sorted Data array no error message is generated but when you click on the element all elements apply the class.

  • Check before iterating *ngIf="!tabelaAnuncioContas.data[0]"

  • Cannot read Property 'data' of Undefined

  • do it only for the !tabelaAnuncioContas

  • If I put <div *ngIf="! tableNew.data[0]"> element is not shown

  • Only the ! tableNew functions are not shown my listing.

  • What are the data composed by SortedData ?

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.