I can not find sql server library (cordova-plugin-

2019-07-28 23:07发布

I installed the cordova-plugin-sqlserver library in the following address. https://www.npmjs.com/package/cordova-plugin-sqlserver

But I do not know how to import it into the project.

Eg.

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BaglantiProvider } from '../../providers/baglanti/baglanti';
import { SqlServer } from 'what shall i write ???????? ';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  constructor(public navCtrl: NavController, public baglanti : BaglantiProvider) {
  }
  test(){
    SqlServer.init("192.168.0.120", "SQLEXPRESS", "sa", "01234567", "dinademo", function(event) {
    alert(JSON.stringify(event));
    }, function(error) {
      alert(JSON.stringify(error));
    });
  }
}

2条回答
We Are One
2楼-- · 2019-07-28 23:43

If you installed the plugin correctly (ionic cordova plugin add https://github.com/SergioDosSantos/cordova-plugin-sqlserver.git ), you should have access to the object via a global variable called SqlServer. You cannot import it as a module.

Because there is not type definition for that object you cannot call it directly (like window.SqlServer): TypeScript will complain that it doesn't exist.

You must at least declare it first (above the @Component decorator):

declare var SqlServer: any;

Now you can use it in your component but you will not benefit from TypeScript: no completion, no checking. For that you would have to create a type definition file.

查看更多
Viruses.
3楼-- · 2019-07-28 23:56

the correct way to reference it from inside the code is:

(<any>window).SqlServer

查看更多
登录 后发表回答