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

    <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>

image.png

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

阅读 2.1k
2 个回答

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

新手上路,请多包涵

条件判断语句应该是明确的:

<div id="themeOne" *ngIf="params?.style == 4 || params?.style == 5 || params?.style == 6">
    <h1>这是模块1</h1>
</div>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题