首页 > 解决方案 > 如何根据传递的 id 激活离子切换?

问题描述

我有很多帖子,我必须只激活用户点击的视图切换。但是当点击一个帖子的按钮时,每个帖子的按钮都是活动的,尽管它没有更新到数据库中。

    <p class="font">
           <strong>Space Type:&nbsp;</strong>{{ post.AvailableSpace.Space.SpaceTypeName }}
                <br> <strong>Address:&nbsp;</strong> {{ post.AvailableSpace.Address}}
                <br><strong>Price:&nbsp;</strong> {{ post.AvailableSpace.Price }} {{ post.AvailableSpace.PriceType.PriceTypeName}}
                <br><strong>No of available rooms:&nbsp;</strong> {{post.AvailableSpace.NoOfRooms}}
                <br>
    </p>

标签: ionic-frameworkssms-2017

解决方案


您应该使用 *ngFor 和 ngClass 来轻松切换某些东西。

.ts 文件

  examples: any = [];
  toggleSection(i) {
    this.examples[i].open = !this.examples[i].open;
    }

.html 文件

<ion-list *ngFor="let item of examples; let i = index">
<ion-item  (click)="toggleSection(i)" [ngClass]="{'section-active': item.open}">
</ion-item>
<ion-card *ngIf="item.open"> Hello </ion-card>
</ion-list>

推荐阅读