I created an ionic 2 application using a visual studio template and am trying to develop offline data synchronization in Azure Mobile Apps functionality. I installed the node "module azure-mobile-apps-client" and using import * as WindowsAzure from 'azure-mobile-apps-client';in app.components.ts and initializing the repository using
Client = new WindowsAzure.MobileServiceClient("url");, but the error shows me as "TypeError: Unable to read openDatabase 'property from undefined".
I also installed the @ ionic-native / sqlite node module and the cordova-sqlite-storage plugin.
See below code:
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { NavController } from 'ionic-angular';
import * as WindowsAzure from 'azure-mobile-apps-client';
var mobileAppClient,
store,
syncContext,
tableName
var useOfflineSync: boolean = true;
@Component({
selector: 'page-about',
templateUrl: 'about.html'
})
export class AboutPage {
constructor(public navCtrl: NavController, public platform:Platform) {
platform.ready().then(() => {
mobileAppClient = new WindowsAzure.MobileServiceClient("https://myapp.azurewebsites.net");
store = new WindowsAzure.MobileServiceSqliteStore('store.db');
store.defineTable({
name: 'todoitem',
columnDefinitions: {
id: 'string',
text: 'string',
complete: 'boolean',
version: 'string'
}
});
syncContext = mobileAppClient.getSyncContext();
syncContext.initialize(store).then((syc) => {
tableName = mobileAppClient.getSyncTable('todoitem');
syncContext.push().then((res) => {
syncContext.pull(new WindowsAzure.Query('todoitem')).then((data) => {
alert(JSON.stringify(data));
}, (err) => {
alert(err);
});
});
}, function (err) {
alert(err);
});
});
}
}
source
share