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));
});
}
}
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 calledSqlServer
. 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):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.
the correct way to reference it from inside the code is:
(<any>window).SqlServer