import { Component } from '@angular/core';
import { HomePage } from './home.page';
@Component({
template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class AppComponent {
rootPage = HomePage;
}
/*
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
*/
import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { AppComponent } from './app.component';
import { HomePage } from './home.page';
@NgModule({
imports: [ IonicModule.forRoot(AppComponent) ],
declarations: [ AppComponent, HomePage ],
entryComponents: [ HomePage ],
bootstrap: [ IonicApp ]
})
export class AppModule { }
/*
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
*/
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
/*
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
*/
<!DOCTYPE html>
<html>
<head>
<title>Ionic 2 QuickStart</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.6.21?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@2.0.0-rc.2/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>
<!--
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
-->
### Ionic 2 Plunk
Basic Ionic 2 plunk based on the Angular QuickStart plunk.
/**
* PLUNKER VERSION
* (based on systemjs.config.js in angular.io)
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(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@2.1.1/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common@2.1.1/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler@2.1.1/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser@2.1.1/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic@2.1.1/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http@2.1.1/bundles/http.umd.js',
'@angular/forms': 'npm:@angular/forms@2.1.1/bundles/forms.umd.js',
'ionic-angular': 'npm:ionic-angular@2.0.0-rc.2',
'rxjs': 'npm:rxjs@5.0.0-beta.12',
'ts': 'npm:plugin-typescript@5.2.7/lib/plugin.js',
'typescript': 'npm:typescript@2.0.7/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';
@Component({
selector: 'page-home',
templateUrl: 'app/home.page.html'
})
export class HomePage {
public states: any[];
public districts: any[];
public cities: any[];
public selectedDistricts: any[];
public selectedCities: any[];
public sState: any;
public sDistrict: any;
appName = 'Ionic App';
constructor(public navController: NavController) {
this.initializeState();
this.initializeDistrict();
this.initializeCity();
}
initializeState(){
this.states = [
{id: 1, name: 'Melaka'},
{id: 2, name: 'Johor'},
{id: 3, name: 'Selangor'}
];
}
initializeDistrict(){
this.districts = [
{id: 1, name: 'Alor Gajah', state_id: 1, state_name: 'Melaka'},
{id: 2, name: 'Jasin', state_id: 1, state_name: 'Melaka'},
{id: 3, name: 'Muar', state_id: 2, state_name: 'Johor'},
{id: 4, name: 'Segamat', state_id: 2, state_name: 'Johor'},
{id: 5, name: 'Shah Alam', state_id: 3, state_name: 'Selangor'},
{id: 7, name: 'Klang', state_id: 3, state_name: 'Selangor'}
];
}
initializeCity(){
this.cities = [
{id: 1, name: 'City of Alor Gajah 1', state_id: 1, district_id: 1},
{id: 2, name: 'City of Alor Gajah 2', state_id: 1, district_id: 1},
{id: 3, name: 'City of Jasin 1', state_id: 1, district_id: 2},
{id: 4, name: 'City of Muar 1', state_id: 2, district_id: 3},
{id: 5, name: 'City of Muar 2', state_id: 2, district_id: 3},
{id: 6, name: 'City of Segamat 1', state_id: 2, district_id: 4},
{id: 7, name: 'City of Shah Alam 1', state_id: 3, district_id: 5},
{id: 8, name: 'City of Klang 1', state_id: 3, district_id: 6},
{id: 9, name: 'City of Klang 2', state_id: 3, district_id: 6}
];
}
setDistrictValues(sState) {
this.selectedDistricts = this.districts.filter(district => district.state_id == sState.id)
}
setCityValues(sDistrict) {
this.selectedCities = this.cities.filter(city => city.district_id == sDistrict.id);
}
}
<ion-header>
<ion-navbar>
<ion-title>{{ appName }}</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-item>
<ion-label>State</ion-label>
<ion-select (ionChange)="setDistrictValues(sState)" [(ngModel)]="sState">
<ion-option [value]="sState" *ngFor = "let sState of states">{{sState.name}} </ion-option>
</ion-select>
</ion-item>
<ion-item *ngIf="selectedDistricts">
<ion-label>District</ion-label>
<ion-select (ionChange)="setCityValues(sDistrict)" [(ngModel)]="sDistrict">
<ion-option [value]="sDistrict" *ngFor = "let sDistrict of selectedDistricts">{{sDistrict.name}}</ion-option>
</ion-select>
</ion-item>
<ion-list *ngIf="selectedCities">
<ion-item *ngFor="let city of selectedCities">
<p>{{city.name}}</p>
</ion-item>
</ion-list>
</ion-content>