angular - 当孩子中没有项目时,角度隐藏父div
问题描述
这是我的html
<div class="d-flex justify-content-around flex-wrap">
<div *ngFor="let f of files$ | async" class="card m-2 card-size">
</div>
</div>
当 observable 中没有项目时files$
,我会看到父级的一个小边框。我已经尝试过border-0
等但没有效果。当子div没有项目时,是否可以隐藏父div?
解决方案
不是最好的解决方案,但你可以这样尝试:
<ng-container *ngIf="files$ | async as files">
<ng-container *ngIf="files.length > 0">
<div class="d-flex justify-content-around flex-wrap">
<div *ngFor="let f of files" class="card m-2 card-size">
</div>
</div>
</ng-container>
</ng-container>
编辑
谢谢@PVermeer!实际上,您可以将第二个*ngIf
放入容器 div 中。
<ng-container *ngIf="files$ | async as files">
<div class="d-flex justify-content-around flex-wrap" *ngIf="files.length > 0">
<div *ngFor="let f of files" class="card m-2 card-size">
</div>
</div>
</ng-container>
推荐阅读
- java - 顶级 build.gradle 已损坏
- c# - 检查多个异步 Web 服务调用的结果
- java - JavaFx MediaPlayer behaves differently in unit test vs application, why?
- javascript - Same result on logging the state after render
- debugging - 如何使用 pyelftools/libdwarf 找到一行代码
- java - 从不同的包(Java)导入嵌套在另一个类中的枚举
- reactjs - How to merge the previous state with the new state in redux?
- snowflake-cloud-data-platform - 雪花变量数据类型
- php - 如何在 Laravel 5.4 中使用 mail() 函数?
- android - 更新到 Catalina mac os 后,ADB 和 Xcode 未检测到连接的设备