javascript - 如何根据布尔值交换内容?
问题描述
我想根据布尔值是真还是假来交换 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>
推荐阅读
- python - 如何用 Python、BeautifulSoup 构建子树?
- python - 创建模型字段以在 django 中存储多个文本输入
- ios - IOS 应用程序接收到的来自 API 的 JSON 与在 Postman 或浏览器中查看的 JSON 之间的差异
- postgresql - 这是一个postgresql错误吗?只有一行不能equal查询但可以like查询
- react-native - 反应原生元素标题背景图像
- android - Gradle 构建守护进程在 CircleCI 中意外消失
- javascript - Discord.js 删除某些角色在频道中发送消息的权限
- ios - 归档归档:Ld */Objects-normal/arm64/test normal arm64
- html - 你如何在正方形纵横比内居中图像并保持响应能力?
- twitter-bootstrap - Bootstrap 固定到底部滚动问题