1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to use @for with NgClass in angular 18

Discussão em 'Angular' iniciado por Marlon Alejandro, Novembro 5, 2024 às 15:12.

  1. I have the following HTML structure in my template:

    <tbody>
    @for(element of elements.value; track $index; let idx = $index, let isEven = $even){
    <tr *ngClass="isEven ? 'some styles here' : 'some other styles otherwise' ">
    <tr>
    }
    <tbody>


    The problem is in this case I'm getting the following error:

    Property 'isEven' does not exist on type 'MyCoomponentName'


    Could someone explain how to use this new @for with the ngClass? My main goal is to paint even <tr> of one color and odds of another, maybe there is another way to do it but not sure.

    I tried *ngClass={{isEven ? '' : ''}} but didn't worked but not sure that's even possible.

    Continue reading...

Compartilhe esta Página