【发布时间】:2019-06-12 21:00:57
【问题描述】:
在我的组件中,我想根据当前的路由参数显示一个文本,在模板中我做了如下:
<h1 *ngIf="mode === 'edit'">Modifier</h1>
<h1 *ngIf="mode === 'add'">Ajouter</h1>
在 ngOnInit 函数中我有这个:
this.route.params.subscribe(params => {
this.id = +params['id'];
this.currentMode = params['mode'];
})
但是当我访问我的组件时,尽管设置了 currentMode,但该元素始终是隐藏的。
我该如何解决这个问题?
【问题讨论】:
-
那么你也应该在你的模板中检查
currentMode。目前您正在检查mode。 -
您不应该使用 currentMode 而不是仅使用 mode 吗?
*ngIf="currentMode === 'edit'"
标签: angular