feat(native): starting native plugins

This commit is contained in:
Max Lynch
2015-09-08 10:50:23 -05:00
parent e875fe500f
commit f35646e63e
6 changed files with 146 additions and 0 deletions

View 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')
})
}
}

View 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>