【发布时间】:2017-11-04 12:37:56
【问题描述】:
我正在使用标志性 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)
);
});
});
}
}
【问题讨论】:
标签: angular