使用Angular ng-if指令关闭HTML标签

时间:2019-05-09 13:16:10

标签: angular angular-ng-if

我有一个带有td的条件表,我想在某些事件之前或之后关闭它。使用NG-IF指令,我无法做到,因为我将TD标签关闭到NG-CONTAINER中。可以这样做吗?

我在这里只剪了一部分代码。一种解决方案是将所有内容都包含进去,并进行有条件的表示,但是之前有很多代码

<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 个答案:

答案 0 :(得分:3)

嗯,不。 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>

答案 1 :(得分:0)

根据HTML规范或Angular,这似乎不正确,在任何时间点上,Hazelcast IMDG内只有一个;with cte(wtype,id,parent,title,ptype,WILevel,ParentTitle) as ( select WorkItemType,wi_id,parent,title,ParentType,0 as WILevel,'' as ParentTitle from tbl_VSTS_AllWorkItems where Parent is null and state<>'Removed' union all select WorkItemType,wi_id,W.parent,W.title,ParentType=t2.wtype,(t2.WILevel+1) as WILevel, t2.title as ParentTitle from tbl_VSTS_AllWorkItems W inner join cte t2 on t2.id=W.Parent where state<>'Removed' ) select * from cte where WILevel=0; ,因此在关闭容器后关闭ng-container

<td>