当我的应用加载时,我喜欢根据存储在SQLite数据库表中的数据加载特定视图。我的数据库结构和我的场景如下:
SQLite数据库:myapp.db
表:设置
表格字段:api_key,active_user_id
当应用加载时,我想获取' api_key'的数据。和' active_user_id'来自SQLite表。
场景1 :如果' api_key'为空或'',我需要加载' 注册'图。
场景2 :如果' api_key'是不是空的'以及' active_user_id'是空的'或者' 0',然后我需要加载' 登录'图
场景3 :如果' api_key'是不是空的'以及' active_user_id'是> 0,然后我需要加载' 信息中心'图。
这是我的app.js
(function() {
var app = angular.module('MyApp', ['ionic', 'ngCordova']);
var db = null;
app.controller('RegistrationCtrl', function($scope, $cordovaSQLite) {
//properties and functions goes in here
});
app.controller('LoginCtrl', function($scope, $cordovaSQLite) {
//properties and functions goes in here
});
app.controller('DashboardCtrl', function($scope, $cordovaSQLite) {
//properties and functions goes in here
});
app.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
window.plugins.sqlDB.copy("myapp.db", 0, function() {
db = $cordovaSQLite.openDB("myapp.db");
}, function(err) {
db = $cordovaSQLite.openDB("myapp.db");
});
});
});
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('registration', {
url: '/registration',
templateUrl: 'templates/registration.html',
controller: 'RegistrationCtrl'
})
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'LoginCtrl'
})
.state('dashboard', {
url: '/dashboard',
templateUrl: 'templates/dashboard.html',
controller: 'DashboardCtrl'
});
$urlRouterProvider.otherwise('/registration');
});
}());

在应用加载时,我在哪里编写代码来获取api_key和active_user_id的值?
如何根据上述方案根据api_key和active_user_id的值加载特定视图?
任何帮助都会非常感激。