Here is the code for two page where I am setting and getting the local data.
Login Page.
export class LoginUserPage {
userId: string = "";
userName: string;
email: string = "";
password: string = "";
url: string;
userList = [];
filteredList = []
constructor(private navController: NavController, platform: Platform, public toastCtrl: ToastController, public storage: Storage,private httpSer: HttpCommonService,public viewCtrl: ViewController) {
}
loginUser() {
this.filteredList = this.userList.filter(function (el) {
return el.userName.toLowerCase().indexOf(this.userId.toLowerCase()) > -1;
}.bind(this));
if (this.filteredList.length > 0) {
this.url = "xyz/" + this.filteredList[0].userId;
this.httpSer.performGET(this.url).subscribe(
response => {
if (response.success) {
this.navController.setRoot(DashboardPage);
this.showToast("Welcome " + response.userName);
this.storage.set('userData', {
userName: response.userName,
userId: this.filteredList[0].userId,
adminId: response.adminId,
adminName: response.adminName,
roleId: response.roleId,
roleName: response.roleName,
action: response.action,
adminRoleName:response.adminRoleName
});
}
},
);
} else {
this.showToast("Please check username");
}
}
}
and in the dashboard page
declare var cordova: any;
declare var window: any;
@Component({
selector: 'page-dashboard',
templateUrl: 'dashboard.html',
providers: [DatePipe]
})
export class DashboardPage {
constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController, public toastCtrl: ToastController,
public alertCtrl: AlertController, private platform: Platform, private datePipe: DatePipe, private storage: Storage, private httpSer: HttpCommonService,
public loadingCtrl: LoadingController) {
this.platform = platform;
this.alertCtrl = alertCtrl;
this.rootPage = DashboardPage;
this.storage = storage;
this.getLocalData();
this.platform.registerBackButtonAction(() => {
this.platform.exitApp();
});
this.platform.ready().then(() => {
debugger;
if (this.platform.is('ios')) {
this.storageDirectory = cordova.file.documentsDirectory;
console.log("Dashboard page");
}
else if (this.platform.is('android')) {
this.storageDirectory = cordova.file.externalDataDirectory;
}
else {
return false;
}
});
}
getLocalData() {
console.log("A");
this.storage.get('userData').then((data) => {
this.userId = data.userId;
this.roleName = data.roleName;
this.action = data.action;
console.log("userId ", this.userId);
})
}
}
Now as above, in login page after I get user details from back end web service I am setting the data in local storage, and in the dashboard page I am getting the local data in ```getLocalData()`` method. On android device it is working perfectly, but on iOS device I am unable to get the data, rather the data is getting stored locally I don’t know.