首页 新闻 会员 周边

angular: 加了 *ngif 的 html 标签始终不显示

0
悬赏园豆:30 [已解决问题] 解决于 2023-09-15 14:37

angular 组件 template 部分的代码

<span *ngif="!isVip" ><a href="https://cnblogs.vip/" target="_blank">升级成为会员</a></span>

class 中对应的变量声明

@Input() isVip? = false;

无论 isVip 是什么值,上面的 span 标签始终不显示,请问如何解决?

问题补充:

后来发现 *ngif 大小写写错了,但改为 *ngIf 后问题依旧

即使改为下面的写法也不行

<span *ngif="true" ><a href="https://cnblogs.vip/" target="_blank">升级成为会员</a></span>
dudu的主页 dudu | 高人七级 | 园豆:30948
提问于:2023-09-15 11:57
< >
分享
最佳答案
0

在 github issue *ngIf doesn't work in Ivy compiled libraries 的评论中找到了原因:

You can't use NgIf without importing CommonModule

在对应组件的 .component.ts 中添加 CommonModule 引用后解决

import { CommonModule } from '@angular/common';
//...
imports: [RouterLink, DecodeHtmlPipe, ElLocatorDirective, CommonModule]
dudu | 高人七级 |园豆:30948 | 2023-09-15 14:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册