How to get result to listpage


#1

how to get result from HomePage to ListPage when click Button

providers/github.ts

import { Injectable } from '@angular/core';  
import { Http, Headers } from '@angular/http';  

@Injectable()
export class GitHubService {  
    constructor(private http: Http) {
    }
    getRepos(username) {
        let repos = this.http.get(`https://api.github.com/users/${username}/repos`);
        return repos;
    }
}

pages/home.html

<ion-content>
    <ion-list inset>
        <ion-item>
            <ion-label>Search</ion-label>
            <ion-input [(ngModel)]="username" type="text"></ion-input>   
    <div padding>
        <button ion-button block (click)="getRepos()">Search</button>
    </div>
</ion-content>

home/home.ts
import { Component } from “@angular/core”;
import { GitHubService } from ‘…/…/services/github’;
import { NavController } from ‘ionic-angular’;
import { DetailsPage } from ‘…/details/details’;

@Component({
    selector: 'page-home',
    templateUrl: 'home.html',
    providers: [GitHubService]
})
export class HomePage {  
    public foundRepos;
    public username;

    constructor(private github: GitHubService,  
                private nav: NavController) {
    }
  
getRepos() {
  let something = this.github.getRepos(this.username) ;
  this.nav.push(ListPagePage, {something});
  }
}

ListPagePage.html

  <ion-list>
  <ion-item *ngFor="let repos of foundRepos" (click)="itemClicked($event,item)">
        <h2> {{ repo.name }}</h2>
        <p>{{ repo.description }}</p>  
      </ion-item>
    </ion-list>

ListPagePage.ts

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { GitHubService } from '../../providers/github';
import { HomePage } from '../home/home';

@Component({
  selector: 'page-list-page',
  templateUrl: 'list-page.html',
  providers: [GitHubService]
})
export class ListPagePage {
 public repos;
 public foundRepos;
 public username;
 public something;

  constructor(private navParams: NavParams, public homepage :HomePage ) {
  this.something = this.navParams.get("something");
  this.something.subscribe(
           data => {
               this.foundRepos = data.json();
           },
           err => console.error(err),
           () => console.log('getRepos completed')
       );
  }
  ionViewDidLoad() {
    console.log('ionViewDidLoad ListPagePage');
  }