import { Component, ViewChild } from '@angular/core';
import { Nav, Platform } from 'ionic-angular';
import { HomePage } from './home.page';
import { ListPage } from './list.page';
@Component({
template: `
<ion-menu [content]="content">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false" ></ion-nav>
`
})
export class AppComponent {
@ViewChild(Nav) nav: Nav;
rootPage = HomePage;
pages: Array<{title: string, component: any}>;
constructor(){
this.pages = [
{ title: 'Home', component: HomePage },
{ title: 'List', component: ListPage }
];
}
openPage(page) {
// Reset the content nav to have just this page
// we wouldn't want the back button to show in this scenario
this.nav.setRoot(page.component);
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule } from 'ionic-angular';
import { AppComponent } from './app.component';
import { HomePage } from './home.page';
import { ListPage } from './list.page';
import { PropertyService } from './property-service';
@NgModule({
imports: [ BrowserModule, IonicModule.forRoot(AppComponent) ],
declarations: [ AppComponent, HomePage, ListPage ],
providers: [PropertyService],
entryComponents: [ HomePage, ListPage ],
bootstrap: [ IonicApp ]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
<!DOCTYPE html>
<html>
<head>
<title>Ionic Servcice issue fail</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.8.12?main=browser"></script>
<script src="https://unpkg.com/systemjs@0.19.40/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<link href="https://unpkg.com/ionic-angular@3.4.0/css/ionic.css" rel="stylesheet">
</head>
<!-- 3. Display the application -->
<body>
<ion-app></ion-app>
<script>
System.import('app').catch(function(err) {
console.error(err);
});
</script>
</body>
</html>
(function (global) {
System.config({
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
}
},
paths: {
// paths serve as alias
'npm:': 'https://unpkg.com/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core@4.2.2/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common@4.2.2/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler@4.2.2/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser@4.2.2/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic@4.2.2/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http@4.2.2/bundles/http.umd.js',
'@angular/forms': 'npm:@angular/forms@4.2.2/bundles/forms.umd.js',
'ionic-angular': 'npm:ionic-angular@3.4.0',
'rxjs': 'npm:rxjs@5.4.1',
'ts': 'npm:plugin-typescript@5.2.7/lib/plugin.js',
'typescript': 'npm:typescript@2.2.1/lib/typescript.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
},
'ionic-angular': {
main: './umd/index.js',
defaultExtension: 'js'
}
}
});
})(this);
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { PropertyService } from './property-service';
@Component({
selector: 'page-home',
templateUrl: 'app/home.page.html'
})
export class HomePage {
private loc: any = { latitude: null, longitude: null };
public props:any[];
private subscription: Subscription;
appName = 'Ionic Service List Issue Demo';
constructor(
public navController: NavController,
private prop: PropertyService
) {
this.props=[];
this.subscription = this.prop.getClosestProps().subscribe(property => {
if (this.props.length >= 5) {
return this.subscription.unsubscribe;
}
this.props.push(property);
});
}
}
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Test App</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-card *ngFor="let prop of props" (click)="propInfo(prop)">
<ion-card-content>
<ion-card-title>{{prop.name}}</ion-card-title>
<p>{{prop.desc}}</p>
</ion-card-content>
</ion-card>
</ion-content>
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
@Component({
selector: 'page-list',
templateUrl: 'app/list.page.html'
})
export class ListPage {
selectedItem: any;
icons: string[];
items: Array<{title: string, note: string, icon: string}>;
constructor(public navCtrl: NavController, public navParams: NavParams) {
// If we navigated to this page, we will have an item available as a nav param
this.selectedItem = navParams.get('item');
// Let's populate this page with some filler content for funzies
this.icons = ['flask', 'wifi', 'beer', 'football', 'basketball', 'paper-plane',
'american-football', 'boat', 'bluetooth', 'build'];
this.items = [];
for (let i = 1; i < 11; i++) {
this.items.push({
title: 'Item ' + i,
note: 'This is item #' + i,
icon: this.icons[Math.floor(Math.random() * this.icons.length)]
});
}
}
itemTapped(event, item) {
// That's right, we're pushing to ourselves!
this.navCtrl.push(ListPage, {
item: item
});
}
}
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>List</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list>
<button ion-item *ngFor="let item of items" (click)="itemTapped($event, item)">
<ion-icon [name]="item.icon" item-left></ion-icon>
{{item.title}}
<div class="item-note" item-right>
{{item.note}}
</div>
</button>
</ion-list>
<div *ngIf="selectedItem" padding>
You navigated here from <b>{{selectedItem.title}}</b>
</div>
</ion-content>
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class PropertyService {
private subject = new Subject<any>();
private fakeData = [
{
name:"property 1",
desc:"property #1"
},
{
name:"property 2",
desc:"property #2"
},
{
name:"property 3",
desc:"property #3"
},
{
name:"property 4",
desc:"property #4"
},
{
name:"property 5",
desc:"property #5"
},
{
name:"property 6",
desc:"property #6"
},
{
name:"property 7",
desc:"property #7"
},
{
name:"property 8",
desc:"property #8"
},
];
getClosestProps() {
let cnt=0;
let myInt = setInterval(()=>{
if (cnt >=this.fakeData.length){
clearInterval(myInt);
this.subject.complete();
}
this.subject.next(this.fakeData[cnt]);
cnt+=1;
},250);
return this.subject.asObservable();
}
}