[英]How to send the data from one page to another page? using ionic and angular
The project has a tab section in that i have two pages 1. recipe page 2. favorite该项目有一个选项卡部分,其中我有两个页面 1. 食谱页面 2. 收藏夹
in recipe page their is a list of recipes and i added a add icon button at the end of each list.在食谱页面中,它们是食谱列表,我在每个列表的末尾添加了一个添加图标按钮。 How to send list from the recipe page to favorite page by clicking the add icon button.
如何通过单击添加图标按钮将列表从食谱页面发送到收藏页面。
pls help me请帮助我
Ionic, angular离子型,angular
If you want to send an option from one page to another, this is a good way.如果您想将选项从一个页面发送到另一个页面,这是一个好方法。
First, you have to list the options and when choosing one, you push to another page首先,您必须列出选项,然后在选择一个时,您推送到另一个页面
In index.html:在 index.html 中:
<ion-card *ngFor= "let elemento of resultado.list; let i = index"></ion-card>
recipes.js:食谱.js:
this.navCtrl.push( FavoritePage,{op: i} );
The most use solution on that type of case is to call services.这种情况下最常用的解决方案是调用服务。 You call a service to store the data that you want, and then call it on the other page.
你调用一个服务来存储你想要的数据,然后在另一个页面上调用它。 If you have any doubts on how to do it and never done a service, feel free to ask.
如果您对如何做有任何疑问并且从未做过服务,请随时提问。
There are two ways that i know.我知道有两种方法。
data.service.ts数据服务.ts
import { Injectable } from '@angular/core';
@Injectable()
export class dataService {
data: string;
setData(data) {
this.data = data;
}
getData(){
return this.data;
}
}
App.component.ts应用组件.ts
import { Component } from '@angular/core';
import { dataService } from './server.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(private dataService: dataService){}
getData() {
retrun this.dataService.getData();
}
}
2) Using the NavController 2) 使用导航控制器
this.navCtrl.push(HomePage, {
data: userData
});
On homepage you can access the passed data like this在主页上,您可以像这样访问传递的数据
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.userData = navParams.get('data');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.