Ionic / Cordova:如何将Cordova插件集成到现有的Ionic项目? [英] Ionic/Cordova: How to integrate Cordova Plugins into existing Ionic project?
问题描述
我有一个Ionic项目,我需要Cordova相机插件(我现在安装成功)。但在我的项目中Camera API仍然不可用,即我抛出错误:
I have an Ionic project where I need the Cordova Camera plugin (which I now installed successfully). But in my project the Camera API is still not available, i.e. I get error thrown:
ReferenceError: Camera is not defined
at Scope.$scope.takePic
如何激活插件API用于Ionic项目?
How do I active the plugin API(s) to be used in an Ionic project? Documentation about this seems to be rather nonexistant or very well hidden.
推荐答案
请按照以下步骤操作:
1。 Include ngCordova before cordova.js
1. Include ngCordova before cordova.js
You can found the same description in the docs.
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
2。在命令行中添加您的插件
You can find this step in the docs in the section of your specific plugin.
ionic plugin add org.apache.cordova.camera
3。请记住,在浏览器中工作时不能使用cordova
因此,当使用 $ cordovaCamera.getPicture
库在内部调用 navigator.camera.getPicture
,在桌面浏览器中开发时不可用。 进一步阅读
So when using the $cordovaCamera.getPicture
the library is calling internally navigator.camera.getPicture
which is not available when developing in the desktop browser. Further reading
ngCordova / Ionic小组目前处理模拟,您可以用来避免类似的问题。
The ngCordova / Ionic team is currently working on mocks you can use to avoid problems like that.
这篇关于Ionic / Cordova:如何将Cordova插件集成到现有的Ionic项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!