javascript Cordova 插件不适用于离子

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25684371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 04:50:49  来源:igfitidea点击:

Cordova plugins not working with ionic

javascriptangularjscordovaionic-frameworkcordova-plugins

提问by Ben Taliadoros

I have an Ionic app built with Angular.

我有一个用 Angular 构建的 Ionic 应用程序。

I am using is Calendar plugin: https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin

我使用的是日历插件:https: //github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin

I want to create events through the plugin and save them to the local device's calendar.

我想通过插件创建事件并将它们保存到本地设备的日历中。

I have added the plugin though:

我已经添加了插件:

cordova plugin add https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin.git

And I try to use it in my controller:

我尝试在我的控制器中使用它:

 ionic.Platform.ready(function(){onError);
    window.plugins.calendar.createEvent(title, location, notes, start, end, onSuccess, onError);
 });

In the browser it says window.plugins is undefined and on the device the error is 'undefined' is not an object (evaluating 'window.plugins.calendar')

在浏览器中,它说 window.plugins 是未定义的,而在设备上,错误是“未定义”不是一个对象(评估“window.plugins.calendar”)

I have searched high and low for this, I cant seem to find a solution that works.

我为此进行了高低搜索,但似乎找不到有效的解决方案。

Any idea how to use a Cordova plugin with Ionic?

知道如何在 Ionic 中使用 Cordova 插件吗?

回答by Ben Taliadoros

The answer was to add

答案是添加

<script src="cordova.js"></script>

And rebuild the Platforms

并重建平台

If still issue not resolved, remove and add the platforms

如果问题仍未解决,请删除并添加平台

回答by manzapanza

Cordova plugins only runs on emulators or real devices.

Cordova 插件只能在模拟器或真实设备上运行。

To test a Cordova app with the browser take a look also to Ripple Emulator (Chrome plugin), but I prefer to test on real devices.

要使用浏览器测试 Cordova 应用程序,还可以查看 Ripple Emulator(Chrome 插件),但我更喜欢在真实设备上进行测试。

Cheers!

干杯!