Skip to content

Instantly share code, notes, and snippets.

@frankyston
Created April 1, 2016 00:32
Show Gist options
  • Select an option

  • Save frankyston/a5eb165043af4d3c6ea3e635e307d316 to your computer and use it in GitHub Desktop.

Select an option

Save frankyston/a5eb165043af4d3c6ea3e635e307d316 to your computer and use it in GitHub Desktop.
Provider and view ionic 2
import {App, Platform} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {TabsPage} from './pages/tabs/tabs';
import {BibleData} from './providers/bible-data';
@App({
template: '<ion-nav [root]="rootPage"></ion-nav>',
providers: [BibleData],
config: {} // http://ionicframework.com/docs/v2/api/config/Config/
})
export class MyApp {
static get parameters() {
return [[BibleData],[Platform]];
}
constructor(bibleData, platform) {
this.rootPage = TabsPage;
bibleData.load();
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
});
}
}
import {Injectable} from 'angular2/core';
import {Http} from 'angular2/http';
Injectable();
export class BibleData {
static get parameters(){
return [[Http]];
}
constructor(http, user) {
this.http = http;
}
load() {
if (this.data) {
// already loaded data
return Promise.resolve(this.data);
}
// don't have the data yet
return new Promise(resolve => {
this.http.get('data/bible2.json').subscribe(res => {
this.data = res.json();
resolve(this.data);
});
});
}
processBook(book) {
return this.load().then(data => {
data.book = {};
data.forEach(thisBook => {
if (thisBook.book == book) {
data.book = thisBook;
}
});
return data.book;
});
}
}
import {Page, ActionSheet} from 'ionic-angular';
import {BibleData} from '../../providers/bible-data';
@Page({
templateUrl: 'build/pages/page1/page1.html'
})
export class Page1 {
static get parameters() {
return [[BibleData]];
}
constructor(bibleData){
this.bibleData = bibleData;
this.items = [];
this.book = {};
this.items.push({name: "Genêsis"});
this.items.push({name: "Êxodo"});
this.items.push({name: "Levítico"});
bibleData.processBook("Gênesis").then(data => this.book = book);
console.log(this.book);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment