angular - 如何在不使用多行代码的情况下在视图中显示或不显示组件
问题描述
我看过很多例子,但我仍然相信可以有一种更简单的方法,而无需在创建的每个组件中包含代码。我的想法不是在我的登录中显示 2 个组件,而是在我的其余组件中显示,是的。
app.component.html
<menu></menu>
<router-outlet></router-outlet>
<footer_component></footer_component>
解决方案
如果您不想渲染 app.component.html 中的所有组件,可以使用带条件的 *ngIf 指令
<menu *ngIf="condition"></menu>
<router-outlet></router-outlet>
<footer_component *ngIf="condition"></footer_component>
推荐阅读
- javascript - 如何在 Yuotube Api 中停止循环,“循环”:0 不起作用
- php - 在 000webhost 上托管 codeigniter 项目
- javascript - 如何从外部 API 获取的数据中动态地将行添加到 HTML 表中?
- jquery - Turnjs图像点击并转到页面
- python - 如何使用 Pandas Python 进行过滤
- php - 尝试访问 int 类型值的数组偏移量 - 对于每个循环
- angular - 如何在角度动画中触发 n 个变量状态(相同状态)?
- import - 如何使用 pyinstaller 打包大型多文件夹项目?
- body-parser - Strapi Body-Parser 文件大小设置
- arrays - 这个问题是否存在任何 O(1) 解决方案?