mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
feat(native): starting native plugins
This commit is contained in:
48
ionic/components/app/test/native/index.ts
Normal file
48
ionic/components/app/test/native/index.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import {Component} from 'angular2/angular2';
|
||||
import {Control, ControlGroup} from 'angular2/forms';
|
||||
|
||||
import {App, Http, Camera, Geolocation} from 'ionic/ionic';
|
||||
|
||||
let testUrl = 'https://ionic-api-tester.herokuapp.com/json';
|
||||
let testUrl404 = 'https://ionic-api-tester.herokuapp.com/404';
|
||||
|
||||
|
||||
@App({
|
||||
templateUrl: 'main.html'
|
||||
})
|
||||
class IonicApp {
|
||||
constructor() {
|
||||
}
|
||||
doGetLocation() {
|
||||
console.log('Getting location');
|
||||
this.gettingLocation = true;
|
||||
Geolocation.getCurrentPosition().then((pos) => {
|
||||
this.gettingLocation = false;
|
||||
console.log('Got location', pos);
|
||||
this.location = pos;
|
||||
}, (err) => {
|
||||
this.gettingLocation = false;
|
||||
console.error('Unable to get location', err);
|
||||
});
|
||||
}
|
||||
doTrackLocation() {
|
||||
this.gettingTrackLocation = true;
|
||||
Geolocation.watchPosition().source.subscribe((pos) => {
|
||||
this.gettingTrackLocation = false;
|
||||
console.log('Got location', pos);
|
||||
this.trackLocation = pos;
|
||||
}, (err) => {
|
||||
this.gettingTrackLocation = false;
|
||||
console.error('Unable to get location', pos);
|
||||
});
|
||||
}
|
||||
getPicture() {
|
||||
Camera.getPicture({
|
||||
|
||||
}).then(data => {
|
||||
console.log('Data', data);
|
||||
}, err => {
|
||||
alert('Unable to take picture')
|
||||
})
|
||||
}
|
||||
}
|
||||
17
ionic/components/app/test/native/main.html
Normal file
17
ionic/components/app/test/native/main.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<ion-view>
|
||||
<ion-content padding>
|
||||
<h2>Camera</h2>
|
||||
<button primary (click)="getPicture()">Get Picture</button>
|
||||
<h2>Geolocation</h2>
|
||||
<button primary (click)="doGetLocation()">Get Location</button>
|
||||
<div>
|
||||
<b *ng-if="gettingLocation">Fetching location...</b>
|
||||
<b *ng-if="location">{{location.coords.latitude}}, {{location.coords.longitude}}</b>
|
||||
</div>
|
||||
<button primary (click)="doTrackLocation()">Track Location</button>
|
||||
<div>
|
||||
<b *ng-if="gettingTrackLocation">Fetching location...</b>
|
||||
<b *ng-if="trackLocation">{{trackLocation.coords.latitude}}, {{trackLocation.coords.longitude}}</b>
|
||||
</div>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
Reference in New Issue
Block a user