From 53b6d813d5db5e00ea7c49111f2318fa93e60f0f Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Mon, 1 Aug 2016 14:25:55 -0500 Subject: [PATCH] note about ng1 observables --- README.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b8b6baa1f..e1be9d43d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Ionic Native wraps plugin callbacks in a Promise or [Observable](https://gist.gi ``` import { Geolocation } from 'ionic-native'; -Geolocation.getCurrentPosition().then(pos => { +Geolocation.getCurrentPosition().then(pos => { console.log('lat: ' + pos.coords.latitude + ', lon: ' + pos.coords.longitude); }); @@ -49,6 +49,23 @@ angular.module('myApp', ['ionic', 'ionic.native']) }); ``` +For services that return observables, the Angular 1 digest cycle must be done manually (currently): + +```javascript +angular.module('myApp', ['ionic', 'ionic.native']) + +.controller('MyCtrl', function($scope, $cordovaGeolocation) { + $scope.takePicture = function() { + $cordovaGeolocation.watchPosition(opts).subscribe(function(p) { + $scope.$apply(function() { + $scope.position = p.coords; + }); + }, function(err) { + }); + }; +}); +``` + ### Runtime Diagnostics Spent way too long diagnosing an issue only to realize a plugin wasn't firing or installed? Ionic Native lets you know what the issue is and how you can resolve it. @@ -57,7 +74,7 @@ Spent way too long diagnosing an issue only to realize a plugin wasn't firing or ## Installation -Run following commmand to install ionic-native in your project. +Run following commmand to install ionic-native in your project. ``` npm install ionic-native --save ```