使用 Angular ng-if 指令关闭 HTML 标记
Closing HTML Tag with Angular ng-if directive
我有一个条件 table,我想在某些事件之前或之后关闭它。使用 NG-IF 指令我不能这样做,因为我将 TD 标签关闭到 NG-CONTAINER 中。可以这样做吗?
我这里只截取了一部分代码。一种解决方案是将所有内容包含在 a 中以进行有条件的表示,但是之前有很多代码
<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>
嗯,不。 Angular 专门检查所有标签是自关闭还是为了编译而关闭。
在 *ngIf 之后关闭 TD 也更有意义。
<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>
根据 HTML 规范或 Angular 这似乎不对,任何时候你在 <td>
中都只有一个 ng-container
所以关闭你的 td
容器关闭后:
<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>
我有一个条件 table,我想在某些事件之前或之后关闭它。使用 NG-IF 指令我不能这样做,因为我将 TD 标签关闭到 NG-CONTAINER 中。可以这样做吗?
我这里只截取了一部分代码。一种解决方案是将所有内容包含在 a 中以进行有条件的表示,但是之前有很多代码
<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>
嗯,不。 Angular 专门检查所有标签是自关闭还是为了编译而关闭。
在 *ngIf 之后关闭 TD 也更有意义。
<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>
根据 HTML 规范或 Angular 这似乎不对,任何时候你在 <td>
中都只有一个 ng-container
所以关闭你的 td
容器关闭后:
<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>