File tree 1 file changed +13
-17
lines changed
1 file changed +13
-17
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- import angular from 'angular' ;
4
-
5
- function ExampleCtrl ( $scope , $cordovaDevice ) {
3
+ function ExampleCtrl ( $scope , CordovaService , $cordovaDevice ) {
6
4
7
5
// ViewModel
8
6
const vm = this ;
@@ -13,22 +11,20 @@ function ExampleCtrl($scope, $cordovaDevice) {
13
11
vm . deviceReadyStatus = 'Cordova not loaded' ;
14
12
vm . deviceInfo = { } ;
15
13
16
- vm . loadDeviceInfo = function ( ) {
17
- $scope . $apply ( function ( ) { //lets make sure angular hears about our update
18
- vm . deviceReady = true ;
19
- vm . deviceReadyStatus = 'Device Ready' ;
20
-
21
- try {
22
- angular . isDefined ( $cordovaDevice . getDevice ( ) ) ; //unfortunately if the plugin is not installed calling this will cause fatal error
23
- vm . deviceInfo = $cordovaDevice . getDevice ( ) ;
24
- }
25
- catch ( e ) {
26
- vm . deviceReadyStatus += ' - Plugin not installed, please run "cordova plugin add cordova-plugin-device"' ;
27
- }
28
- } ) ;
14
+ let loadDeviceInfo = ( ) => {
15
+ vm . deviceReady = true ;
16
+ vm . deviceReadyStatus = 'Device Ready' ;
17
+
18
+ try {
19
+ angular . isDefined ( $cordovaDevice . getDevice ( ) ) ; //unfortunately if the plugin is not installed calling this will cause fatal error
20
+ vm . deviceInfo = $cordovaDevice . getDevice ( ) ;
21
+ }
22
+ catch ( e ) {
23
+ vm . deviceReadyStatus += ' - Plugin not installed, please run "cordova plugin add cordova-plugin-device"' ;
24
+ }
29
25
} ;
30
26
31
- document . addEventListener ( 'deviceready' , vm . loadDeviceInfo , false ) ;
27
+ CordovaService . ready . then ( ( ) => loadDeviceInfo ( ) ) ;
32
28
}
33
29
34
30
export default {
You can’t perform that action at this time.
0 commit comments