【发布时间】:2020-10-03 00:22:12
【问题描述】:
如何在 Angular2+ 的 index.html 中使用 *ngIf 条件。我想使用*ngIf 根据条件加载标签,因为我在本地存储中有一个值。这是我的代码,但它不起作用。
<head *ngIf="localStorage.getItem('theme_token') === 'site-layout'"></head
当我使用脚本标记时,它会在 javascript 中获取主题标记的值。
<script>
var _val = localStorage.getItem('theme_token'); /// This part is working returning me the value.
</script>
注意:我不想隐藏。我必须使用
*ngIf渲染它 条件。
【问题讨论】:
-
您可以将 index.html 放入 app.component.html 中,然后您可以使用 ngIf
标签: javascript html angular angular8