Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic/Cordova: How to integrate Cordova Plugins into existing Ionic project?

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 

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.

like image 285
BadmintonCat Avatar asked May 15 '14 08:05

BadmintonCat


People also ask

How do I add plugins to Ionic project?

First, log into the Ionic Hub, then navigate to the Native Plugins Keys page. Click Assign to App , then New App . Enter a name, then click Create App .

How do I update my Cordova plugin to Ionic?

Update Cordova Platforms versions are currently installed, run cordova platform list (If you are using Ionic, this information is also included in the ionic info output). This will return a list of “Installed platforms” with their version number: λ cordova platform list Installed platforms: android 5.0.


1 Answers

Follow these steps:

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. Add your plugin on the command line

You can find this step in the docs in the section of your specific plugin.

ionic plugin add org.apache.cordova.camera

3. Remember that cordova is not available while working in the browser

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

The ngCordova / Ionic team is currently working on mocks you can use to avoid problems like that.


You can download ngCordova here: http://ngcordova.com/docs/install/


Update: There is Ionic Native now, it's like ngCordova but for ES6 and TypeScript.

like image 171
e382df99a7950919789725ceeec126 Avatar answered Sep 18 '22 07:09

e382df99a7950919789725ceeec126