Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 287
Josh Avatar asked Apr 06 '15 10:04

Josh


People also ask

What are events in ionic?

Events is a publish-subscribe style event system for sending and responding to application-level events across your app.

How do I start an Ionic app?

Starting a new Ionic app is incredibly simple. From the command line, run the ionic start command and the CLI will handle the rest. Please enter the full name of your app. You can change this at any time.

How do you start an Ionic 3 project?

Use the --type option to start projects using older versions of Ionic. For example, you can start an Ionic 3 project with --type=ionic-angular . Use --list to see all project types and templates.

How do I add a back button in ionic?

Hardware Back Button in Capacitor and Cordova​The @capacitor/app package must be installed in Capacitor apps to use the hardware back button. When running in a Capacitor or Cordova application, Ionic Framework will emit an ionBackButton event when a user presses the hardware back button.


1 Answers

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.
    });
});
like image 128
Keval Avatar answered Sep 19 '22 12:09

Keval