在离子框架中显示隐藏

问题描述 投票:0回答:1

我想为我的离子应用程序显示隐藏功能:

以下是我到目前为止在xyz.html文件中所做的事情:

<ion-item>    
<p class="font_c_2 gra_reg" (click)="onPtagClick(part.reg_id)"  *ngIf="!PtagClicked">
          {{part.fsp_partner_location}}
</p>
<p class="font_c_2 gra_reg" *ngIf="PtagClicked" (click)="onPtagClick1(part.reg_id)"  style="white-space:normal;">
          {{part.fsp_partner_location}}
</p>
</ion-item>

我的xyz.ts文件

export class xyzpage{
public PtagClicked: boolean = false;

public onPtagClick(id) {         
    {        
     this.PtagClicked = !this.PtagClicked;          
    }           
  }
 public onPtagClick1(id) {
   {            
    this.PtagClicked = false;   

    }           
  }
}

我的问题是,我在此页面上创建了动态数字,如果我点击1项,它会显示/隐藏所有项目的数据而不是我点击的数据。

我想如果我可以为ngIf创建动态值,问题就会解决,但是我试过并且不能因为我是离子的新手。

任何帮助将不胜感激。

我安装了最新的IONIC。

谢谢

javascript angular ionic-framework ionic3
1个回答
0
投票

使用Renderer2 addClass,setStyle或任何你想要的东西,将元素引用传递给你的click事件处理程序

这里有一个Demo

HTML

<ion-item *ngFor="let item of items">
  <h3 #text>{{item}}</h3>
  <button ion-button item-right (click)="onShow(text)">Show</button>
  <button ion-button color="danger" item-right (click)="onHide(text)">Hide</button>
</ion-item>

TS

import { Component, Renderer2 } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

public items: string[] = [
    "Item 1",
    "Item 2",
    "Item 3",
    "Item 4",
    "Item 5",
    "Item 6",
    "Item 7",
    "Item 8",
    "Item 9",
    "Item 10",   
];

  public PtagClicked: boolean = false;

  constructor(public navCtrl: NavController, private render: Renderer2) { }

  public onShow(controlToShow) {
    this.render.setStyle(controlToShow, 'visibility', 'visible');
  }
  public onHide(controlToHide) {
    this.render.setStyle(controlToHide, 'visibility', 'hidden');
  }

}
© www.soinside.com 2019 - 2024. All rights reserved.