我正在使用Ionic 2。
我关注了this,并执行了以下操作:
cordova plugin add cordova.plugins.diagnostic npm install -g typings typings install dt~cordova --save --global
app.ts
if (window.cordova && cordova.plugins) {
cordova.plugins.diagnostic.isLocationEnabled(function (enabled) {
alert("Location is " + (enabled ? "enabled" : "disabled"));
}, function (error) {
alert("The following error occurred: " + error);
});
}
}
我收到以下错误:
error TS2339: Property 'diagnostic' does not exist on type 'CordovaPlugins'.
我注意到window.cordova
是undefined
。
如果有人可以建议我如何使用Cordova插件,我将不胜感激。
由于
答案 0 :(得分:0)
因此,对于Ionic 2,请尝试使用window [' plugins']代替cordova.plugins。