如何在应用离子正确的方式Deviceready?离子、正确、方式、如何在

由网友(恋我半世的流离)分享简介:我科尔多瓦和离子型移动应用程序。在其上的应用程序开始后加载的默认页是需要与SQLLite插件工作。 I have Cordova and Ionic based mobile application. On the default page which is loaded after the start of the...

我科尔多瓦和离子型移动应用程序。在其上的应用程序开始后加载的默认页是需要与SQLLite插件工作。

I have Cordova and Ionic based mobile application. On the default page which is loaded after the start of the application is need to work with SQLLite plugin.

https://github.com/brodysoft/Cordova-SQLitePlugin

问题是,视图包含

ng-init="setData()"

这是调用其中与SQL精简版插件工作的控制器方法。而且由于该方法的不初始化deviceready事件之前被调用(插件只能deviceready事件之后被初始化)。

Which is calling the controller method where is worked with SQL Lite plugin. And because of the the method is called before the deviceready event is not initialized (plugin can be initialized only after deviceready event).

所以,我想这种解决方法:

So I tried this workaround:

.run(function($ionicPlatform) {
  $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);
      db = window.sqlitePlugin.openDatabase({name:"callplanner"});
    }

但是,这不是为我工作。

But this not working for me.

所以我尝试第二个解决方案:

So i tried second solution:

.factory('cordova', function () {
  return {
      test: function(){
          document.addEventListener("deviceready", this.ready, false);
      },
      ready: function(){
            alert("Ready");
            db = window.sqlitePlugin.openDatabase({name:"callplanner"});
      }

  }
})

在控制器初始化我尝试:

and in controller init i tried:

cordova.test();

但是,这是不工作(devicereadfy是NG-初始化后,解雇了)。

But this is not working to (devicereadfy is fired after ng-init).

之后,我发现这篇文章:

After that i found this article:

http://java.dzone.com/articles/ionic-and- cordovas-deviceready

但我不知道如何把闪屏之前的应用程序已经准备好,以及如何设置超时时间。

But i did not understand how to put "splash screen" before app is ready and how to set timeout.

有别人的想法我怎么能解决这个问题?

Have somebody idea how can I solve this problem?

任何建议或帮助非常感谢。

Many Thanks for any advice or help.

推荐答案

您需要反转这一点,首先你处理科尔多瓦deviceready事件,然后你开始angularjs应用。像这样的:

You need to invert this, first you handle the cordova "deviceready" event and then you start the angularjs app. Like this:

首先从HTML / body标签取下的NG-应用程序属性

First remove the the ng-app attribute from the html/body tag

启动角应用的devireready后:

Start the angular app after the devireready:

<script>
  document.addEventListener('deviceready', function() { 
    angular.bootstrap(document, ['YourAppName']);
  }, false);
  var YourAppName = angular.module('YourAppName', []);
</script>

类似的问题:

科尔多瓦+ Angularjs +设备就绪 Initialize PhoneGap的经过我angularJs应用deviceready Cordova + Angularjs + Device Ready Initialize my angularJs App after Phonegap deviceready
阅读全文

相关推荐

最新文章