【问题标题】:ngIf doesn't display the intended outputngIf 不显示预期的输出
【发布时间】:2017-10-05 13:39:07
【问题描述】:

我在向用户隐藏内容时遇到了问题。例如,从top 1到3,用户的top 1是视觉的,top 2是口头的。它应该显示视觉和口头的内容,但会隐藏第二部分。

如果从前 1 到 3,我只有语言而没有视觉,它将显示第二部分并隐藏第一部分。我究竟做错了什么?

 //Hides content if user is Both visual and verbal
 <div *ngFor="let styleElement of styles">
  <ion-slides *ngIf="styleElement.first == 'Visual' || styleElement.second == 'Visual' || styleElement.third == 'Visual' ||

        styleElement.first == 'Visual' && styleElement.second == 'Verbal' ||
        styleElement.first == 'Visual' && styleElement.third == 'Verbal' ||
        styleElement.second == 'Visual' && styleElement.first == 'Verbal' ||

        styleElement.second == 'Visual' && styleElement.third == 'Verbal' ||
        styleElement.third == 'Visual' && styleElement.first == 'Verbal' ||
        styleElement.third == 'Visual' && styleElement.second == 'Verbal'
        ">
    <ion-slide *ngFor="let slide of universeSlides">
      <br>
      <img [src]="slide.image" class="slide-image" />
    </ion-slide>
  </ion-slides>
</div>


 //Hides this if user is only verbal
// the 2nd part im referring to
<div *ngFor="let styleElement of styles">
  <div *ngIf="
  styleElement.first != 'Visual' && styleElement.first != 'Verbal' ||
  styleElement.first != 'Visual' && styleElement.second != 'Verbal' ||
  styleElement.first != 'Visual' && styleElement.third != 'Verbal'
    ">
.....

【问题讨论】:

  • 您是否尝试过控制台日志记录以确保一切都按预期进行?您也可以尝试将一些条件句括在括号中。

标签: html angular ionic-framework angular-ng-if


【解决方案1】:

这样试试

<div
      *ngIf="((styleElement.first != 'Visual' && styleElement.first != 'Verbal')
       || (styleElement.first != 'Visual' && styleElement.second != 'Verbal')
       || (styleElement.first != 'Visual' && styleElement.third != 'Verbal'))"
    >

【讨论】:

  • 请查看已编辑的问题。我已经修改了我的场景。谢谢
  • @AngularNewbie,请将您的问题恢复到原始状态,如果 RaviTeja 回答了您的原始问题,请选择它。如果您有新问题,请将其作为单独的问题发布,至少,将您的所有更新发布在 -----UPDATE----- 的文本块下
猜你喜欢
  • 2014-09-19
  • 1970-01-01
  • 1970-01-01
  • 2015-07-28
  • 1970-01-01
  • 1970-01-01
  • 2020-04-06
  • 2022-11-26
  • 2021-07-13
相关资源
最近更新 更多