我正在使用iconic 2/angular 2,并使用NativeStorage插件。
我有一个服务器URL,可以让用户更改,并且应该被保留。我非常新于angular,所以不确定在哪里调用NativeStorage.getItem是最好的。
显然,它应该是一个用户启动应用程序时首先执行的地方,并且此时NativeStorage已经初始化。
我的当前代码会使应用程序在加载屏幕上挂起:
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { NativeStorage } from 'ionic-native';
import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, storage: NativeStorage) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
platform.ready().then(() => {
NativeStorage.getItem('CHAT_SERVER_HOST').then(
(val) => { alert("init:" + val); },
error => alert(error)
);
});
});
}
}