Ionic 2 Offline Data Sync using Azure Mobile Apps throws TypeError: Cannot read openDatabase property from undefined

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';
//declare var WindowsAzure: any;
import * as WindowsAzure from 'azure-mobile-apps-client';

var mobileAppClient, // Connection to the Azure Mobile App backend
    store,  // Sqlite store to use for offline data sync
    syncContext, // Offline data sync context
    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");
            // Create the sqlite store
            store = new WindowsAzure.MobileServiceSqliteStore('store.db');

            store.defineTable({
                name: 'todoitem',
                columnDefinitions: {
                    id: 'string',
                    text: 'string',
                    complete: 'boolean',
                    version: 'string'
                }
            });

            // Get the sync context from the client
            syncContext = mobileAppClient.getSyncContext();

            // Initialize the sync context with the store\
            syncContext.initialize(store).then((syc) => {

                // Get the local table reference.
                tableName = mobileAppClient.getSyncTable('todoitem');

                // Sync local store to Azure table when app loads, or when login complete.
                syncContext.push().then((res) => {

                    // Push completed
                    // Pull items from the Azure table after syncing to Azure.
                    syncContext.pull(new WindowsAzure.Query('todoitem')).then((data) => {
                        alert(JSON.stringify(data));
                    }, (err) => {
                        alert(err);
                    });

                });

            }, function (err) {
                alert(err);
            });
        });

  }

}
+4
source share

Source: https://habr.com/ru/post/1690172/


All Articles