简体   繁体   English

如何将我点击的值传递给下一页

[英]How to pass the value that I clicked to next page

I am new to ionic, and I have design an ionic application, I want to pass the first page value to the second page. 我刚接触离子技术,并且已经设计了离子应用程序,因此我希望将第一页的值传递给第二页。 I will attach 2 photo to explain it more clearly. 我将附上2张照片,以更清楚地说明它。

This is the first picture 这是第一张图片

First Page 第一页

第一页

Once I clicked the white box button on the first page, I want the icon to be appear on the second page like this. 单击第一页上的白框按钮后,我希望这样的图标出现在第二页上。

Second Page 第二页

第二页

If I click Electricity on the first page, the icon on second page will show what I clicked on the first page, the icon what you see is I hard code it. 如果我在第一页上单击“电”,则第二页上的图标将显示我在第一页上单击的内容,您看到的图标是我对其进行硬编码的。 I have no idea how to make it works, does anyone know how to make it works ? 我不知道如何使其运作,有人知道如何使其运作吗?

This is my code for the first page button, 这是我的首页按钮代码,

<ion-col col-6 style="text-align:center;" >
  <button ion-button (click)="problem()" class="divButtonBox">
   <ion-icon class="logo-flash" name="flash"></ion-icon>
  </button>
</ion-col>

Here is the TS for problem(); 这是problem()的TS;

problem(){
  this.navCtrl.push(ProblemPage)  
}

Here is the code for viewing second page, I hard code it because I don't know how to pass the value or string. 这是查看第二页的代码,我对其进行了硬编码,因为我不知道如何传递值或字符串。

<ion-col col-5 style="text-align:center;">
    <ion-icon name="flash" class="logo"></ion-icon>
</ion-col>

This is done using ionics NavController . 这是使用NavController完成的。 You can simply add optional data to the push() call: 您可以简单地将可选数据添加到push()调用中:

this.navCtrl.push(ProblemPage, {
  problemType: 'electricity'
});

And you can retrieve it on the ProblemPage like this using NavParams : 您可以使用NavParamsProblemPage上检索它:

export class ProblemPage {
  public problemType;

  constructor(private navParams: NavParams) {
   this.problemType = navParams.get('problemType');
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM