Cannot call method 'paste' of undefined for ngCordova with ionic and phonegap build


#1

I am using the clipboard plugin https://github.com/VersoSolutions/CordovaClipboard
i am using ionic ngCordova extention set and building my app using the phonegap build service.

phonegap version 3.7.0

i have added the plugin like so and it works great with the JavaScript way:

     window.plugins.clipboard.paste(function (text) { alert(text); });

but when i use the $cordovaClipboard i am getting this error:

  module.controller('ClipboardCtrl', function($scope, $cordovaClipboard) {
  $cordovaClipboard.paste().then(function (result) {
         // success, use result
        }, function () {
         // error
           });
     });



     TypeError: Cannot call method 'paste' of undefined

        at Object.paste (file:///android_asset/www/js/ng-cordova.min.js:7:15146)

        at l.$scope.mypastefun(file:///android_asset/www/js/myCtrl.js:54:22)

        at file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:229:303

        at file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:388:5713

        at l.$eval (file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:156:305)

        at l.$apply (file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:157:6)

        at HTMLButtonElement. (file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:388:5695)

        at HTMLButtonElement.c (file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:63:389)

        at n (file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:22:384)

        at t (file:///android_asset/www/lib/ionic/js/ionic.bundle.min.js:22:216) ionic.bundle.min.js:133

    (anonymous function) ionic.bundle.min.js:133

    (anonymous function) ionic.bundle.min.js:107

    l.$apply ionic.bundle.min.js:157

    (anonymous function) ionic.bundle.min.js:388

    c ionic.bundle.min.js:63

    n ionic.bundle.min.js:22

    t ionic.bundle.min.js:22

    l ionic.bundle.min.js:22

    t ionic.bundle.min.js:22

    l ionic.bundle.min.js:22

This happens only on the build service and not in the CLI.


#2

From what I can see:

  • You have included ngCordova js file
  • You’ve injected ngCorodva into the Ionic project (you would receive a different error instead)
  • $cordovaClipboard is injected into the controller

Questions:

Have you included ngCordova js before cordova js file?
Is this ClipboardCtrl the first controller that runs in your application?


#3

Have you included ngCordova js before cordova js file?
A:yes i have

Is this ClipboardCtrl the first controller that runs in your application?
A: No

i am for now doing it the JavaScript way

     window.plugins.clipboard.paste(function (text) { alert(text); });

will post and let you know after further testing