离子应用启动事件

Jos*_*osh 6 angularjs ionic

我的angularjs离子应用程序有问题.登录时我们正在加载各种设置.如果我终止该应用并重新启动它,则不会加载这些设置.

我需要知道在应用程序启动时是否有一个事件被调用,以便我可以重新加载我的应用程序设置.

谢谢

Kev*_*val 11

您可以添加代码行以在YourIndex.html的Controller中加载设置,也可以将代码放在其下$ionicPlatform.ready.

选项1:index.html的控制器中运行它,因为每次打开应用程序时,都会加载此控制器.

var myApp = angular.module('myApp', ['ionic']);

myApp.config(function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/')

    $stateProvider.state('index', {
        url: '/',
        controller: 'IndexCtrl',
    })
});

myApp.controller('IndexCtrl', function($scope) {
    //load your settings from localStorage or DB where you saved.
});
Run Code Online (Sandbox Code Playgroud)

选项2:每次Ionic呼叫deviceReady时呼叫.

var myApp = angular.module('myApp', ['ionic']);
myApp.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
        //load your settings from localStorage or DB where you saved.
    });
});
Run Code Online (Sandbox Code Playgroud)