2015-04-06 133 views
5

我的angularjs離子應用程序出現問題。在登錄期間我們正在加載各種設置。如果我殺了應用程序並重新啓動它,這些設置不會被加載。離子應用程序啓動事件

我需要知道在應用程序啓動時是否有一個事件被調用,以便我可以重新加載我的應用程序設置。

謝謝

回答

11

您可以添加的代碼行加載設置,無論是在YourIndex.html的控制器或者你可以把這些代碼$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:每離子調用deviceReady時間打電話。

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