我使用Angular,我想在本例中使用*ngIf else
(从版本4开始提供):
<div *ngIf="isValid">
content here ...
</div>
<div *ngIf="!isValid">
other content here...
</div>
我怎样才能用ngIf else
实现相同的行为呢?
我使用Angular,我想在本例中使用*ngIf else
(从版本4开始提供):
<div *ngIf="isValid">
content here ...
</div>
<div *ngIf="!isValid">
other content here...
</div>
我怎样才能用ngIf else
实现相同的行为呢?
Angular 4 and 5:
使用else
:
<div *ngIf="isValid;else other_content">
content here ...
</div>
<ng-template #other_content>other content here...</ng-template>
您还可以使用then else
:
<div *ngIf="isValid;then content else other_content">here is ignored</div>
<ng-template #content>content here...</ng-template>
<ng-template #other_content>other content here...</ng-template>
或仅then
人:
<div *ngIf="isValid;then content"></div>
<ng-template #content>content here...</ng-template>
Demo:个
Details:个
<ng-template>
:Angular自己实现的<template>
标签是according to MDN:
HTML
<template>
元素是一种保存客户端的机制