Ionic应用程序启动事件

6

我有一个问题,我的angularjs ionic应用程序,在登录期间我们正在加载各种设置。如果我杀死应用程序并重新启动它,这些设置将不会被加载。

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

谢谢

2个回答

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.
});

选项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.
    });
});

0

如果有人在寻找Ionic 2或3的解决方案:

export class MyApp {

constructor() {
        platform.ready().then(() => {

            //DO WHATEVER

        });
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接