我如何使用“*ngIf else"? [英] How can I use "*ngIf else"?

查看:37
本文介绍了我如何使用“*ngIf else"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angular,我想在这个例子中使用 *ngIf else(从版本 4 开始可用):

内容在这里...

<div *ngIf="!isValid">其他内容在这里...

如何使用 ngIf else 实现相同的行为?

解决方案

Angular 4 和 5:

使用else:

内容在这里...

<ng-template #other_content>这里有其他内容...</ng-template>

你也可以使用then else:

<div *ngIf=isValid;then content else other_content">这里被忽略了</div><ng-template #content>内容在这里...</ng-template><ng-template #other_content>这里有其他内容...</ng-template>

或者 then 单独:

<ng-template #content>内容在这里...</ng-template>

演示:

Plunker

详情:

:是 Angular 自己对