Hi, I know there’s a lot of ressources to answer this question but I need a little boost to understand with an example from my project. I’m new to Ionic and Angular 2 so I’m sure I’ll be able to understand better with your help. I need to understand where to put things.
I’d like to pass item.points to an other component.
home.ts : Here’s my home.ts :
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Action1 } from '../action1/action1';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class Home {
items = [];
btnName: any = 'Edit';
flag: any = false;
constructor(public navCtrl: NavController) {
this.items = [
{
id: 'action1',
points: 0,
label: 'never : details',
link: 'Action1'
},
{
id: 'action2',
points: 0,
label: 'never : details',
link: 'Action2'
},
];
}
reorderItems(indexes) {
let element = this.items[indexes.from];
this.items.splice(indexes.from, 1);
this.items.splice(indexes.to, 0, element);
}
actionBtn() {
if (this.btnName == 'Edit') {
this.btnName = 'Done';
this.flag = true;
}
else {
this.btnName = 'Edit';
this.flag = false;
}
};
goToPage(test) {
console.log('test');
this.navCtrl.push(Action1);
}
rarely(SlidingItem, item) {
item.points = 25;
SlidingItem.close();
}
sometimes(SlidingItem, item) {
item.points = 50;
SlidingItem.close();
}
often(SlidingItem, item) {
item.points = 75;
SlidingItem.close();;
}
always(SlidingItem, item) {
item.points = 100;
SlidingItem.close();
}
}
home.html : Here’s my home.html
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
<ion-buttons end>
<button ion-button small clear (click)="actionBtn();">
{{btnName}}
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-card>
<ion-item>
<ion-avatar item-left>
<ion-icon class="custom-icon" name="home"></ion-icon>
</ion-avatar>
<h2></h2>
<p [innerHTML]="testing"></p>
</ion-item>
</ion-card>
<ion-list sliding="{{flag2}}">
<ion-item-group reorder="{{flag}}" (ionItemReorder)="reorderItems($event)">
<ion-item-sliding *ngFor="let item of items" #SlidingItem >
<ion-item (click)="goToPage(Action1)">
{{item.id}}
<p>{{item.label}}</p>
<p>{{item.points}}</p>
</ion-item>
<ion-item-options side="right">
<button ion-button (click)="always(SlidingItem, item)">
Always
</button>
<button ion-button (click)="often(SlidingItem, item)">
Often
</button>
<button ion-button (click)="sometimes(SlidingItem, item)">
Sometimes
</button>
<button ion-button (click)="rarely(SlidingItem, item)">
Rarely
</button>
</ion-item-options>
</ion-item-sliding>
</ion-item-group>
</ion-list>
</ion-content>
statistics. ts : I’d like to pass item.points to an other component. This one :
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Home } from '../pages/home/home';
@Component({
selector: 'page-statistics',
templateUrl: 'statistics.html'
})
export class Statistics {
constructor(public navCtrl: NavController) {
}
}
statistics.html : Where I wrote 10 actions and 180 points here :
<!--
Generated template for the Energy page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar>
<ion-title>Statistics</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-card>
<ion-item>
<ion-avatar item-left>
<img src="../assets/img/stats-bars.png">
</ion-avatar>
<h2>10 actions</h2>
<p>180 points</p>
</ion-item>
</ion-card>
</ion-content>
Thanks !