如何根据布尔值交换内容?
How to exchange content depending on a boolean?
我想根据布尔值是真还是假来交换 page.html 中的一些内容。所以我看到你可以用 <ng-content>
创建这样的东西,但不知何故这没有成功。我收到此错误:Error: Template parse errors: <ng-content> element cannot have content.
我还注意到必须有一些方法可以删除旧内容。
page.html
<ion-card>
<!-- content to move away when bool true-->
</ion-card>
<div *ngIf="!checked">
<ng-content>
<ion-card>
<!-- new content when bool false-->
</ion-card>
</ng-content>
</div>
有两个单独的条件句对你有用吗?
<ion-card *ngIf="checked">
<!-- content to move away when bool true-->
</ion-card>
<ion-card *ngIf="!checked">
<!-- new content when bool false-->
</ion-card>
如果这不起作用,您可以使用 开关
<div [ngSwitch]="checked">
<ion-card *ngSwitchCase="true">
<!-- content to move away when bool true-->
</ion-card>
<ion-card *ngSwitchCase="false">
<!-- new content when bool false-->
</ion-card>
</div>
我想根据布尔值是真还是假来交换 page.html 中的一些内容。所以我看到你可以用 <ng-content>
创建这样的东西,但不知何故这没有成功。我收到此错误:Error: Template parse errors: <ng-content> element cannot have content.
我还注意到必须有一些方法可以删除旧内容。
page.html
<ion-card>
<!-- content to move away when bool true-->
</ion-card>
<div *ngIf="!checked">
<ng-content>
<ion-card>
<!-- new content when bool false-->
</ion-card>
</ng-content>
</div>
有两个单独的条件句对你有用吗?
<ion-card *ngIf="checked">
<!-- content to move away when bool true-->
</ion-card>
<ion-card *ngIf="!checked">
<!-- new content when bool false-->
</ion-card>
如果这不起作用,您可以使用 开关
<div [ngSwitch]="checked">
<ion-card *ngSwitchCase="true">
<!-- content to move away when bool true-->
</ion-card>
<ion-card *ngSwitchCase="false">
<!-- new content when bool false-->
</ion-card>
</div>