在角度2的div之间切换,并根据要显示/隐藏的条件设置值

时间:2018-06-15 15:20:38

标签: angular hidden ngfor

我正在使用(Hide/show individual items inside ngFor

中提供的解决方案

如何根据条件设置pinMe [j]的值?我有这样的情况,我需要在div之间切换,但也决定首先根据条件显示什么。以下是您的信息的示例代码。

<table>
  <thead>
    <tr>
      <th>Manufacturer</th>
      <th>Model</th>
      <th>BIOSFamily</th>
      <th>BIOSDate</th>
      <th>SerialNumber</th>
    </tr>
  </thead>
  <tbody>
<?php
  $dir = "/Apache24/htdocs/reservation/JR";
  if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
      foreach(glob("*.json") as $filename) {
        $data = file_get_contents($filename);
        $testing = json_decode($data, true);
        foreach($testing as $testing) {
          echo "<tr>";
          echo "<td>", $testing['Comments']['Manufacturer'], "</td>";
          echo "<td>", $testing['Comments']['Model'], "</td>";
          echo "<td>", $testing['Comments']['BIOSFamily'], "</td>";
          echo "<td>", $testing['Comments']['BIOSDate'], "</td>";
          echo "<td>", $testing['Comments']['SerialNumber'], "</td>";
          echo "</tr>";
        }
      }
    }
  }
?>
  </tbody>
</table>

上一页不允许我发布评论,因此将其创建为新问题。

提前致谢!

1 个答案:

答案 0 :(得分:0)

我会使用ng-if来显示隐藏div或任何元素。

<ion-card *ngFor="let feed of feeds; let j=index">
<ion-card-header> 
    <h1 (click)="pinMe[j] = !pinMe[j]">PinnedView</h1>
</ion-card-header>
<ion-card-content>
    <div ng-if="feed.isPinned = '1'" [hidden]="!pinMe[j]"> </div>
    <div ng-if="feed.isPinned != '1'" [hidden]=enter code here"pinMe[j]"> </div> 
</ion-card-content>
</ion-card>

参考:http://www.codelord.net/2015/07/28/angular-performance-ng-show-vs-ng-if/