我正在使用iconic 2/angular 2并使用NativeStorage插件。Angular 2阅读本地存储的最佳地点
我有一个服务器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)
);
});
});
}
}
这个组件 – Vik
@Vik我更新了我的代码,我认为我们可以先获取数据,然后检查平台/插件 –