如何包含和使用cordova插件 [英] How to include and use cordova plugins

查看:198
本文介绍了如何包含和使用cordova插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在离子应用中遇到了 cordova插件。谷歌搜索了一整天,还没有大赢。

I'm struggling with cordova plugins in my ionic app. Been googling whole day, no big win yet.

这就是我要做的事情 - 在我的应用程序中打开一个带有navbar存在的网页。我发现 cordova-themeable 可能会解决这个问题

here's what I'm trying to do - open a web page inside my app with navbar present. I found that cordova-themeable might work that out

...但是......

...however...

我安装了它

$ cordova plugin add cordova-plugin-themeablebrowser

好的,它存在

$ cordova plugin list
cordova-plugin-camera 2.2.0 "Camera"
cordova-plugin-compat 1.0.0 "Compat"
cordova-plugin-console 1.0.3 "Console"
cordova-plugin-device 1.1.2 "Device"
cordova-plugin-splashscreen 3.2.2 "Splashscreen"
cordova-plugin-statusbar 2.1.3 "StatusBar"
cordova-plugin-themeablebrowser 0.2.15 "ThemeableBrowser"
cordova-plugin-whitelist 1.2.2 "Whitelist"
ionic-plugin-keyboard 2.2.0 "Keyboard"

现在,我正试图在控制器中使用它函数

now, I'm trying to use it in controller function

$scope.doStuff = function doStuff() {
    cordova.ThemeableBrowser.open('http://apache.org', '_blank', {
        ...

并在我的 .html 文件中调用

<ion-item ng-click="doStuff()">

我收到以下错误

ReferenceError: cordova is not defined at Scope.doStuff

在我的 index.html ,我有

<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

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

请帮忙,谢谢

推荐答案

要添加一个正确的插件,即如果你想使用 cordova adomb插件

To add a plugin you are doing right, i.e. if you want to use cordova adomb plugin:

cordova plugin add cordova-admob

关于错误:您是在浏览器还是在真实设备中调试?通常在浏览器中,您应该使用

Regarding to the error: Are you debugging in browser or in real device? Normally in browser, you should use

cordova platform add browser
phonegap serve

(我建议您使用 phonegap serve insetad cordova发送,因为它有时效果更好,但不应该有所不同)

(I recommend you to use phonegap serve insetad of cordova serve as sometimes it works better, but shouldn't make the difference)

另一种调试应用的方法是使用 android远程调试

Another way to debug apps is to use android remote debug.

这篇关于如何包含和使用cordova插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆