My service code includes two functions - one for creating a native storage with IP and port, and the other for retrieving values from the native storage.
DatabaseService
export class DatabaseService {
...
public ip: string;
public port: string;
...
public createConnectionInfo(ip: string, port: string) {
NativeStorage.setItem('connectionStorage', { ip: ip, port: port })
.then(
() => console.log('Stored Connection Information!'), //Working
error => console.error('Error storing connection information', error)
);
}
...
public getConnectionInfo() {
this.platform.ready().then(() => {
NativeStorage.getItem('connectionStorage').then(data => {
this.ip = data.ip; // Storing IP in public variable
this.port = data.port;
console.log(this.ip); //Works
}, error => {
this.navCtrl.push(SettingPage);
});
});
}
...
}
SettingPage
export class SettingPage {
connection: any;
service: DatabaseService;
ip: string;
port: string;
constructor(public navCtrl: NavController, platform: Platform, service: DatabaseService) {
this.service = service;
platform.ready().then(() => {
if(true){
console.log(this.service.ip+" IP FROM THE SERVICE"); \\Trying to retrieve IP from service.
}
});
}
...
}
I successfully created and retrieved values from the native storage, but facing difficulty passing them from my service to the setting page. Seeking guidance on resolving this issue. Your help is appreciated as I work towards finding a solution.
My Ionic Info
Cordova CLI: 6.3.1
Gulp version: CLI version 3.9.1
Gulp local:
Ionic Framework Version: 2.0.0-rc.1
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Mac OS X El Capitan
Node Version: v6.7.0
Xcode version: Xcode 7.3.1 Build version 7D1014