I\'m developing an application Ionic, Angular and Cordova and I\'m looking for the best way to call Cordova plugins in Javascript while developing in the browser. What is the be
As cordova.js
is only available when you are running application in device or emulator. So there is no way that you can use cordova plugins in browsers.As you need to put a check if(navigator.globalization)
on every plugin call for testing on browsers, so i will suggest you to make your own wrapper or functions above these calls, some sort of global function which will call these plugins functions.
Here is a sample with plain javascript.
function MyGlobalizationService(){
};
MyGlobalizationService.prototype.getPreferredLanguage = function(onSuccess, onError){
if(navigator.globalization) {
navigator.globalization.getPreferredLanguage(onSuccess, onError);
}
}
window.myGlobalizationService = new MyGlobalizationService();
And then use window.myGlobalizationService
functions anywhere in your application.