角度[ngIf],[ngIfElse]和[ngIfElseIf]

问题描述

我现在有以下代码

<ng-container *ngIf="someCondition">
    <ng-template [ngIf]="cd.typedType === 'first'" [ngIfElse]="Second">
      <div class="row">
      first
      </div>
    </ng-template>
    <ng-template #Second>
      <div class="row">
      second
      </div>
    </ng-template>
</ng-container>

它正在工作。 如果有其他方法可以使用吗?要创建类似的内容

<ng-container *ngIf="someCondition">
    <ng-template [ngIf]="cd.typedType === 'first'" [ngIfElseIf]="cd.typedType === 'Second'" [ngIfElse]="cd.typedType === 'Third'>
      <div class="row">
      first
      </div>
    </ng-template>
    <ng-template #Second>
      <div class="row">
      second
      </div>
    </ng-template>
    <ng-template #Third>
      <div class="row">
      third
      </div>
    </ng-template>
</ng-container>

那么要使用基本的if / elseif / else在3个不同的模板之间移动吗?

解决方法

ngSwitch似乎是您正在寻找的答案!

data

在这里获取更多信息: angular.io/api/common/NgSwitchCase

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...