Я не знаю, является ли это лучшим вариантом, но я обычно - когда я могу использовать plugova - использую «сервис» для хранения значений или объекта.например, ваш main.app.ts может иметь вид
//Use "declare" to have variables that store cordova and pluggins before Component declaration
declare var StatusBar: any;
declare var cordova: any;
declare var window:any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
//In constructor you inject a service (you can called cordovaService)
cosntructor(private cordovaService:CordovaService){}
//You must add in ngAfterViewInit a document.addEventListener('device ready')
ngAfterViewInit() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
}
onDeviceReady() {
//Typical you use to defined aht happens when, pause, resume,backbutton..
document.addEventListener('pause', this.onPause.bind(this), false);
document.addEventListener('resume', this.onResume.bind(this), false);
document.addEventListener("backbutton", this.onBackKeyDown.bind(this), false);
//MoreOver you have there your "plugging"
//for example, if add StatusBar pluging you have "StatusBar"
//So you can
StatusBar.hidden();
//Or if you have a variable "StatusBar" in your service
this.cordovaService.StatusBar=StatusBar
//so, any component that inject "CordovaService" would make a
//this.cordovaService.StatusBar.hide() or this.cordovaService.StatusBar.show()
//idem if you has imported getAppVersion, you can do
cordova.getAppVersion.getVersionNumber().then(version => {
console.log(version)
});
//Or make
this.cordovaService.cordova=cordova
//so, any component that inject "CordovaService" would make a
//this.cordovaService.cordova.getAppVersion.getVersionNumber().then(version =>
// {
// console.log(version)
// });
}
В случае, если плагин "сейчас играет", я полагаю, вы можете использовать эту "технику"