-1

i have a conditional table with a td that i want to close before or after some events. With NG-IF directive i can't do it because of i close the TD tag into NG-CONTAINER. Is possible to do this?

I cut here only a part of code. One solution can be to enclose all and into a to have conditional rapresentation but ther's a lot of code before

<ng-container>
  <td>
    some other code
    <ng-container *ngIf="riga.value['type'] === 'title';else other">
       {{riga.value['description']}}
         </td>
    </ng-container>
    <ng-template #other>
      <ng-container>
         {{riga.value['otherdescription']}}
           </td>
      </ng-container>
    </ng-template>
</ng-container>

2 Answers2

3

Well, no. Angular specifically checks that all tags are either self closed or closed for the sake of compilation.

Closing the TD after the *ngIf makes a lot more sense too.

  <td>
    some other code
    <ng-container *ngIf="riga.value['type'] === 'title';else other">
       {{riga.value['description']}}
    </ng-container>
    <ng-template #other>
         {{riga.value['otherdescription']}}
    </ng-template>
 </td>
misha130
  • 5,457
  • 2
  • 29
  • 51
0

As per HTML specifications or Angular this doesn't seem right, any point of time you will have only one ng-container inside <td> so close your td after the containers are closed :

<ng-container>
  <td>
    some other code

     <ng-container *ngIf="riga.value['type'] === 'title';else other">
       {{riga.value['description']}}
    </ng-container>

    <ng-template #other>
      <ng-container>
         {{riga.value['otherdescription']}}

      </ng-container>
    </ng-template>

 </td>
</ng-container>
nircraft
  • 8,242
  • 5
  • 30
  • 46