Created
May 26, 2015 13:59
-
-
Save dejancencelj/1859d0569f5eb93df9ee to your computer and use it in GitHub Desktop.
ngCordova $cordovaBatteryStatus correct use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module('starter', ['ionic', 'starter.controllers', 'starter.services',]) | |
| .run(function ($ionicPlatform, $cordovaBatteryStatus, $ionicLoading) { | |
| $ionicPlatform.ready(function () { | |
| // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard | |
| // for form inputs) | |
| if (window.cordova && window.cordova.plugins.Keyboard) { | |
| cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); | |
| //cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); | |
| //This disables scrolling | |
| cordova.plugins.Keyboard.disableScroll(true); | |
| } | |
| if (window.StatusBar) { | |
| // required | |
| StatusBar.hide(); | |
| } | |
| $rootScope.$on('$cordovaBatteryStatus:status', function (e, result) { | |
| //$ionicLoading.show({template: 'Batery status: ' + result.level, noBackdrop: true, duration: 2000}); | |
| $rootScope.cordovaBatteryStatus.batteryLevel = result.level; // (0 - 100) | |
| $rootScope.cordovaBatteryStatus.isPluggedIn = result.isPlugged; // bool | |
| }); | |
| $rootScope.$on('$cordovaBatteryStatus:critical', function (e, result) { | |
| $rootScope.cordovaBatteryStatus.batteryLevel = result.level; // (0 - 100) | |
| $rootScope.cordovaBatteryStatus.isPluggedIn = result.isPlugged; // bool | |
| }); | |
| $rootScope.$on('$cordovaBatteryStatus:low', function (e, result) { | |
| $rootScope.cordovaBatteryStatus.batteryLevel = result.level; // (0 - 100) | |
| $rootScope.cordovaBatteryStatus.isPluggedIn = result.isPlugged; // bool | |
| }); | |
| }); | |
| //Global object to use in any template | |
| $rootScope.cordovaBatteryStatus = {}; | |
| //Some dummy values. This will be changed on battery state change. | |
| $rootScope.cordovaBatteryStatus.batteryLevel = 100; | |
| $rootScope.cordovaBatteryStatus.isPluggedIn = false; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment