How to use a cordova plugin with Ionic?

I’ve downloaded this into my project holder and in my controller I do like this

angular.module(‘starter.controllers’, []).controller(‘secondCtrl’, function($scope, $stateParams) {


But I got ReferenceError: cordova is not defined error. How to use a plugin of cordova?

do you have these lines in your index.html?

<script src="ionic.bundle.min.js"></script>
<script src="cordova.js"></script>

also, you should include ionic in your module dependency

Also, you need to perform your testing on a device and not in the browser. If you have the cordova.js script line in your index.html and still getting this error, then you are probably not testing in a device. Some plugins will work in the emulator and others require testing on an actual device because the physical hardware must be present, e.g. the camera plugin needs an actual camera. Also, the cordova library needs some time to load so if your app is executing the plugin immeadiately, you will need to wrap the code in the platform ready event…

$ionicPlatform.ready(function() {
  $cordovaPlugin.someFunction().then(success, error);

There is some good info at the ngCordova site. This is a library that grew out of Ionic and provides a standard interface for using the cordova plugins. Unfortunately, your YouTube plugin does not appear to be provided. However, there are still some great best practices info on the site and in the library code. Give it a look…

I use ionic start blank command to generate my template, yes I do have that included.

so ionic can’t use cordova plugin? that’s weird.

try making a function

$scope.playVideo = function(id) {

from this topic