I am using IBM MobileFirst Foundation 8.0, Ionic 2 and typescript for building a Cordova application for iOS and Android.
i have installed cordova-plugin-mfp-jsonstore
and cordova-plugin-mfp
but when trying to initialize a JSONStore collection using below code it is not working. I am getting an error saying JSONStore is undefined
.
mfpJSONStorageConnector.initGlobalCollections()
If I add the same code inside timeout
as follows I get WL.JSONStore
as [object Object]
and mfpJSONStorageConnector.initGlobalCollections()
is working fine.
setTimeout(function(){
}, 8000);
If i remove settimeout , application will break and mfpJSONStorageConnector.initGlobalCollections
will not work
eg:
constructor(public platform: Platform, public alertCtrl: AlertController, public events: Events,
public renderer : Renderer,
public mfpJSONStorageConnector: MFPJSONStorageConnector) {
let self = this;
platform.ready().then(() => {
StatusBar.styleDefault();
});
self.renderer.listenGlobal('document', 'mfpjsloaded', () => {
setTimeout(function(){
mfpJSONStorageConnector.initGlobalCollections().then(function(status) {
authenticationService.getLastLoggedInUser().then((lastLoggedInUser) => {
Splashscreen.hide();
}).catch((ex) => {
//Error
});
});
}, 8000);
});
UPDATES
am using cordova-plugin-mfp-jsonstore
not cordova-plugin-jsonstore
sorry for the confusion
Try adding a listener on 'mfpjsonjsloaded'. That event is fired when the JSONStore plugin completes loading.
renderer.listenGlobal('document', 'mfpjsonjsloaded', () => {
console.log('--> MFP JSONStore API init complete');
...
}