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.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With