Josh
Josh

Reputation: 189

ionic application startup event

I have a problem with my angularjs ionic application. During login we're loading various settings. If I kill the app and re-launch it these settings are not loaded.

I need to know if there's an event that is being invoked when the application launches so that I can reload my app settings.

Thank you

Upvotes: 6

Views: 9522

Answers (2)

justnajm
justnajm

Reputation: 4534

In case some one looking for ionic 2 or 3, solution:

export class MyApp {

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

            //DO WHATEVER

        });
    }
}

Upvotes: 0

Keval
Keval

Reputation: 3389

You can add the lines of code to load the settings either in YourIndex.html's Controller or you can put that code under $ionicPlatform.ready.

Option 1: Run it inside your index.html's controller, because every time you open your app, this controller will be loaded.

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

Option 2: Call every time Ionic calls deviceReady.

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

Upvotes: 11

Related Questions