angular 使用*ngIf判断多条件无效,如何解决?

作者站长头像
站长
· 阅读数 16
    <div id="themeOne" *ngIf="params?.style == 4 || 5 || 6">
       <h1>这是模块1</h1> 
   </div>

   <div id="themeOne" *ngIf="params?.style == 7 || 8 || 9">
       <h1>这是模块2</h1>
   </div>

angular 使用*ngIf判断多条件无效,如何解决?

两个并列的*ngIf为什么会导致下面的判断无效呢?

回复
1个回答
avatar
test
2024-07-16

params?.style == 4 || 5 || 6,js中没有这个语法,应该说这个写法不是你想象的那样,可以这样写[4, 5, 6].includes(params?.style)

回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容